c++ - QWidget::render() on QImage -


i have window contents want export .png file. i'm using it's render function render on qimage:

qlog("image export mode"); const qstring refpath = seq_->item(0)->path(0); qimage refimg(refpath); const qsize imgsize = refimg.size(); qlog("image size: " << imgsize); q_assert(mapwin_); mapwin_->resize(imgsize); // window doesn't seem fit image first time around, // once , disregard result - no idea why happens. mapwin_->showimage(refimg); qimage winimage(mapwin_->size(), qimage::format_argb32); emit mapfit(); qpainter painter(&winimage); emit renderwindow(&painter);  emit message("exporting images"); emit startprogress(itemindices_.size());  // iterate on indices of selected images in sequence (int = 0; < itemindices_.size(); ++i) {     const int itemidx = itemindices_.at(i);     q_assert(itemidx >= 0);     const seqitem *item = seq_->item(itemidx);     q_assert(item->mapexists());     qlog("item " << << " (" << itemidx << "): '" << item->filename(0) << "'");     qloginc;      // iterate on selected displacement components     (int ci = 0; ci < cci::val_count; ++ci)     {         const cci::valueid id = cci::val_id[ci];         if (!dcomp_.active(id)) continue;         const qstring label = valueidwrapper(id).shortname();         qlog("active value: " << label);          mapwin_->setvalueid(id);         emit mapindexupdate(itemidx);         emit mapfit();         emit renderwindow(&painter);          const qstring exportpath = dirpath_ + "/" + item->filename(0).remove(".bmp", qt::casesensitive) + "_" + label + ".png";         winimage.save(exportpath);     }      emit makeprogress();     qlogdec; } 

i's done emiting signal gui thread (emit renderwindow) following:

void mapwindow::renderon(qpainter *image) {     render(image, qpoint(), qregion(), qwidget::drawchildren); } 

unfortunately when run code qt assert: [error window][1] after emiting signal. there can go wrong when try draw qwidget qimage?

the whole callstack on assert (with information deduced it's problem renderon method, since it's last before exception):

qt5cored.dll!qt_message_fatal(qtmsgtype __formal, const qmessagelogcontext & context, const qstring & message) line 1571    c++ qt5cored.dll!qmessagelogger::fatal(const char * msg, ...) line 781  c++ qt5cored.dll!qt_assert(const char * assertion, const char * file, int line) line 2967   c++ qt5widgetsd.dll!qgraphicsscenebsptreeindexprivate::estimateitems(const qrectf & rect, qt::sortorder order, bool onlytoplevelitems) line 379 c++ qt5widgetsd.dll!qgraphicsscenebsptreeindex::estimatetoplevelitems(const qrectf & rect, qt::sortorder order) line 535    c++ qt5widgetsd.dll!qgraphicssceneprivate::drawitems(qpainter * painter, const qtransform * const viewtransform, qregion * exposedregion, qwidget * widget) line 4689   c++ qt5widgetsd.dll!qgraphicsview::paintevent(qpaintevent * event) line 3540    c++ qt5widgetsd.dll!qwidget::event(qevent * event) line 8831    c++ qt5widgetsd.dll!qframe::event(qevent * e) line 540  c++ qt5widgetsd.dll!qabstractscrollarea::viewportevent(qevent * e) line 1200    c++ qt5widgetsd.dll!qgraphicsview::viewportevent(qevent * event) line 2963  c++ qt5widgetsd.dll!qabstractscrollareaprivate::viewportevent(qevent * event) line 102  c++ qt5widgetsd.dll!qabstractscrollareafilter::eventfilter(qobject * o, qevent * e) line 118    c++ qt5cored.dll!qcoreapplicationprivate::sendthroughobjecteventfilters(qobject * receiver, qevent * event) line 1072   c++ qt5widgetsd.dll!qapplicationprivate::notify_helper(qobject * receiver, qevent * e) line 3712    c++ qt5widgetsd.dll!qapplication::notify(qobject * receiver, qevent * e) line 3681  c++ qt5cored.dll!qcoreapplication::notifyinternal(qobject * receiver, qevent * event) line 965  c++ >qt5cored.dll!qcoreapplication::sendspontaneousevent(qobject * receiver, qevent * event) line 227   c++ qt5widgetsd.dll!qwidgetprivate::sendpaintevent(const qregion & tobepainted) line 5628   c++ qt5widgetsd.dll!qwidgetprivate::drawwidget(qpaintdevice * pdev, const qregion & rgn, const qpoint & offset, int flags, qpainter * sharedpainter, qwidgetbackingstore * backingstore) line 5569  c++ qt5widgetsd.dll!qwidgetprivate::paintsiblingsrecursive(qpaintdevice * pdev, const qlist<qobject *> & siblings, int index, const qregion & rgn, const qpoint & offset, int flags, qpainter * sharedpainter, qwidgetbackingstore * backingstore) line 5761    c++ qt5widgetsd.dll!qwidgetprivate::drawwidget(qpaintdevice * pdev, const qregion & rgn, const qpoint & offset, int flags, qpainter * sharedpainter, qwidgetbackingstore * backingstore) line 5619  c++ qt5widgetsd.dll!qwidgetprivate::paintsiblingsrecursive(qpaintdevice * pdev, const qlist<qobject *> & siblings, int index, const qregion & rgn, const qpoint & offset, int flags, qpainter * sharedpainter, qwidgetbackingstore * backingstore) line 5761    c++ qt5widgetsd.dll!qwidgetprivate::paintsiblingsrecursive(qpaintdevice * pdev, const qlist<qobject *> & siblings, int index, const qregion & rgn, const qpoint & offset, int flags, qpainter * sharedpainter, qwidgetbackingstore * backingstore) line 5748    c++ qt5widgetsd.dll!qwidgetprivate::paintsiblingsrecursive(qpaintdevice * pdev, const qlist<qobject *> & siblings, int index, const qregion & rgn, const qpoint & offset, int flags, qpainter * sharedpainter, qwidgetbackingstore * backingstore) line 5748    c++ qt5widgetsd.dll!qwidgetprivate::paintsiblingsrecursive(qpaintdevice * pdev, const qlist<qobject *> & siblings, int index, const qregion & rgn, const qpoint & offset, int flags, qpainter * sharedpainter, qwidgetbackingstore * backingstore) line 5748    c++ qt5widgetsd.dll!qwidgetprivate::drawwidget(qpaintdevice * pdev, const qregion & rgn, const qpoint & offset, int flags, qpainter * sharedpainter, qwidgetbackingstore * backingstore) line 5619  c++ qt5widgetsd.dll!qwidgetprivate::paintsiblingsrecursive(qpaintdevice * pdev, const qlist<qobject *> & siblings, int index, const qregion & rgn, const qpoint & offset, int flags, qpainter * sharedpainter, qwidgetbackingstore * backingstore) line 5761    c++ qt5widgetsd.dll!qwidgetprivate::drawwidget(qpaintdevice * pdev, const qregion & rgn, const qpoint & offset, int flags, qpainter * sharedpainter, qwidgetbackingstore * backingstore) line 5619  c++ qt5widgetsd.dll!qwidgetprivate::render(qpaintdevice * target, const qpoint & targetoffset, const qregion & sourceregion, qflags<enum qwidget::renderflag> renderflags) line 5705    c++ qt5widgetsd.dll!qwidget::render(qpainter * painter, const qpoint & targetoffset, const qregion & sourceregion, qflags<enum qwidget::renderflag> renderflags) line 5145  c++ qt5widgetsd.dll!qwidget::render(qpaintdevice * target, const qpoint & targetoffset, const qregion & sourceregion, qflags<enum qwidget::renderflag> renderflags) line 5068   c++ ccigui.exe!mapwindow::renderon(qimage * image) line 453 c++ ccigui.exe!mapwindow::qt_static_metacall(qobject * _o, qmetaobject::call _c, int _id, void * * _a) line 475 c++ qt5cored.dll!qmetacallevent::placemetacall(qobject * object) line 487   c++ qt5cored.dll!qobject::event(qevent * e) line 1239   c++ qt5widgetsd.dll!qwidget::event(qevent * event) line 9105    c++ qt5widgetsd.dll!qmdisubwindow::event(qevent * event) line 2917  c++ qt5widgetsd.dll!qapplicationprivate::notify_helper(qobject * receiver, qevent * e) line 3716    c++ qt5widgetsd.dll!qapplication::notify(qobject * receiver, qevent * e) line 3681  c++ qt5cored.dll!qcoreapplication::notifyinternal(qobject * receiver, qevent * event) line 965  c++ qt5cored.dll!qcoreapplication::sendevent(qobject * receiver, qevent * event) line 224   c++ qt5cored.dll!qcoreapplicationprivate::sendpostedevents(qobject * receiver, int event_type, qthreaddata * data) line 1593    c++ qt5cored.dll!qeventdispatcherwin32::sendpostedevents() line 1242    c++ qwindowsd.dll!qwindowsguieventdispatcher::sendpostedevents() line 84    c++ qt5cored.dll!qt_internal_proc(hwnd__ * hwnd, unsigned int message, unsigned __int64 wp, __int64 lp) line 416    c++ [external code]  qt5cored.dll!qeventdispatcherwin32::processevents(qflags<enum qeventloop::processeventsflag> flags) line 818    c++ qwindowsd.dll!qwindowsguieventdispatcher::processevents(qflags<enum qeventloop::processeventsflag> flags) line 74   c++ qt5cored.dll!qeventloop::processevents(qflags<enum qeventloop::processeventsflag> flags) line 129   c++ qt5cored.dll!qeventloop::exec(qflags<enum qeventloop::processeventsflag> flags) line 204    c++ qt5widgetsd.dll!qdialog::exec() line 542    c++ ccigui.exe!corr2dproject::handle_exportshow(int type, int seqidx) line 387  c++ ccigui.exe!ccigui::slot_anal_exportclicked() line 1324  c++ ccigui.exe!ccigui::qt_static_metacall(qobject * _o, qmetaobject::call _c, int _id, void * * _a) line 464    c++ qt5cored.dll!qmetaobject::activate(qobject * sender, int signaloffset, int local_signal_index, void * * argv) line 3715 c++ qt5cored.dll!qmetaobject::activate(qobject * sender, const qmetaobject * m, int local_signal_index, void * * argv) line 3579    c++ qt5widgetsd.dll!qabstractbutton::clicked(bool _t1) line 304 c++ qt5widgetsd.dll!qabstractbuttonprivate::emitclicked() line 536  c++ qt5widgetsd.dll!qabstractbuttonprivate::click() line 528    c++ qt5widgetsd.dll!qabstractbutton::mousereleaseevent(qmouseevent * e) line 1133   c++ qt5widgetsd.dll!qwidget::event(qevent * event) line 8679    c++ qt5widgetsd.dll!qabstractbutton::event(qevent * e) line 1090    c++ qt5widgetsd.dll!qpushbutton::event(qevent * e) line 674 c++ qt5widgetsd.dll!qapplicationprivate::notify_helper(qobject * receiver, qevent * e) line 3716    c++ qt5widgetsd.dll!qapplication::notify(qobject * receiver, qevent * e) line 3276  c++ qt5cored.dll!qcoreapplication::notifyinternal(qobject * receiver, qevent * event) line 965  c++ qt5cored.dll!qcoreapplication::sendspontaneousevent(qobject * receiver, qevent * event) line 227    c++ qt5widgetsd.dll!qapplicationprivate::sendmouseevent(qwidget * receiver, qmouseevent * event, qwidget * alienwidget, qwidget * nativewidget, qwidget * * buttondown, qpointer<qwidget> & lastmousereceiver, bool spontaneous) line 2770  c++ qt5widgetsd.dll!qwidgetwindow::handlemouseevent(qmouseevent * event) line 556   c++ qt5widgetsd.dll!qwidgetwindow::event(qevent * event) line 211   c++ qt5widgetsd.dll!qapplicationprivate::notify_helper(qobject * receiver, qevent * e) line 3716    c++ qt5widgetsd.dll!qapplication::notify(qobject * receiver, qevent * e) line 3160  c++ qt5cored.dll!qcoreapplication::notifyinternal(qobject * receiver, qevent * event) line 965  c++ qt5cored.dll!qcoreapplication::sendspontaneousevent(qobject * receiver, qevent * event) line 227    c++ qt5guid.dll!qguiapplicationprivate::processmouseevent(qwindowsysteminterfaceprivate::mouseevent * e) line 1792  c++ qt5guid.dll!qguiapplicationprivate::processwindowsystemevent(qwindowsysteminterfaceprivate::windowsystemevent * e) line 1582    c++ qt5guid.dll!qwindowsysteminterface::sendwindowsystemevents(qflags<enum qeventloop::processeventsflag> flags) line 626   c++ qwindowsd.dll!qwindowsguieventdispatcher::sendpostedevents() line 85    c++ qt5cored.dll!qt_internal_proc(hwnd__ * hwnd, unsigned int message, unsigned __int64 wp, __int64 lp) line 416    c++ [external code]  qt5cored.dll!qeventdispatcherwin32::processevents(qflags<enum qeventloop::processeventsflag> flags) line 818    c++ qwindowsd.dll!qwindowsguieventdispatcher::processevents(qflags<enum qeventloop::processeventsflag> flags) line 74   c++ qt5cored.dll!qeventloop::processevents(qflags<enum qeventloop::processeventsflag> flags) line 129   c++ qt5cored.dll!qeventloop::exec(qflags<enum qeventloop::processeventsflag> flags) line 204    c++ qt5cored.dll!qcoreapplication::exec() line 1229 c++ qt5guid.dll!qguiapplication::exec() line 1528   c++ qt5widgetsd.dll!qapplication::exec() line 2977  c++ ccigui.exe!main(int argc, char * * argv) line 41    c++ ccigui.exe!winmain(hinstance__ * __formal, hinstance__ * __formal, char * __formal, int __formal) line 113  c++ [external code]  

is there can go wrong when try draw qwidget qimage?

yes there is. documentation render overload taking painter states painter must active, means should used during paint event.

consider using other overload takes qpaintdevice.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -