c++ - Qt sending image between dialog -
i'm writing simple application 2 dialogs, first 1 original image, sent dialog , processed. image processed sent first dialog:
imagedialog::imagedialog(qwidget *parent) : qdialog(parent), ui(new ui::imagedialog) { ui->setupui(this); ui->graphicsview->setscene(&mscene); mpixmapitem = new qgraphicspixmapitem(); connect( this, signal( sigcommitimage(qimage) ), parent, slot( updateimage(qimage) ) ); } imagedialog::~imagedialog() { delete ui; delete mpixmapitem; } void imagedialog::processimage(const qimage &image ) { cv::mat tmp(image.height(),image.width(),cv_8uc4,(uchar*)image.bits(),image.bytesperline()); cv::cvtcolor(tmp, tmp, cv_rgba2gray); mimage = qimage( (uchar*)tmp.data, tmp.cols, tmp.rows, tmp.step, qimage::format_indexed8 ); mpixmapitem->setpixmap(qpixmap::fromimage(mimage)); mscene.clear(); mscene.addpixmap(qpixmap::fromimage(mimage)); mscene.setscenerect(0, 0, mimage.width(), mimage.height()); ui->graphicsview->fitinview(mpixmapitem, qt::keepaspectratio); } void imagedialog::on_buttonbox_accepted() { emit( sigcommitimage( mimage ) ); }
and there's snippet main window
mpixelinfodialog = new pixelinfodialog( ); connect( this, signal( sigpixelinfodialog(qpixmap, qpointf) ), mpixelinfodialog, slot( updateclip(qpixmap, qpointf) ) ); mimagedialog = new imagedialog( ); connect( this, signal( sigimagedialog(qimage) ), mimagedialog, slot( processimage(qimage) ) ); void mainwindow::updateimage(const qimage &image) { showimage( image ); } void mainwindow::showimage(const qimage &image) { mimage = image; mpixmapitem->setpixmap(qpixmap::fromimage(image)); mscene.clear(); mscene.addpixmap(qpixmap::fromimage(image)); mscene.setscenerect(0, 0, image.width(), image.height()); ui->graphicsview->fitinview(mpixmapitem, qt::keepaspectratio); } void mainwindow::on_action_open_triggered() { qstring path = qfiledialog::getopenfilename(); if( path.isempty() ) { return; } qimage image(path); if( image.isnull() ) return; showimage( image ); /* * update other open dialogs */ if( mimagedialog->isenabled() ) { emit( sigimagedialog( mimage ) ); } }
the image loaded, sent imagedialog , processed, when try send image, result bunch of random pixel or application crash in
mpixmapitem->setpixmap(qpixmap::fromimage(image));
i can't figure what's happening because i'm doing same operations. advice? in advance
Comments
Post a Comment