c++ - Qt - Segfault on QDrag exec -
i working on project qt 4.8.5 , c++.
i created custom widget called itemview , reimplemented methods drag , drop. problem is, segfaults on qdrag::exec(). tried compile in debug mode , works.
here code :
std::pair<aitem const *, unsigned int> *pair = new std::pair<aitem const *, unsigned int>(_item, _nb); std::ostringstream oss; oss << pair; qdrag *dr = new qdrag(this); qmimedata *data = new qmimedata; data->settext(oss.str().c_str()); dr->setmimedata(data); dr->exec();
and here backtrace
#0 0x00007ffff4b33c6a in strlen () /usr/lib/libc.so.6 #1 0x00007ffff7adc425 in xsetcommand () /usr/lib/libx11.so.6 #2 0x00007ffff7ae0831 in xsetwmproperties () /usr/lib/libx11.so.6 #3 0x00007ffff5cc9a07 in qwidgetprivate::create_sys(unsigned long, bool, bool) () /usr/lib/libqtgui.so.4 #4 0x00007ffff5c8142d in qwidget::create(unsigned long, bool, bool) () /usr/lib/libqtgui.so.4 #5 0x00007ffff5c8997a in qwidget::setvisible(bool) () /usr/lib/libqtgui.so.4 #6 0x00007ffff5cc0bcf in ?? () /usr/lib/libqtgui.so.4 #7 0x00007ffff5cc1e15 in ?? () /usr/lib/libqtgui.so.4 #8 0x00007ffff5c4c064 in qdrag::start(qflags<qt::dropaction>) () /usr/lib/libqtgui.so.4 #9 0x000000000041d8da in itemview::makedrag (this=0x2e31db0) @ src/qt/views/itemview.cpp:155 #10 0x000000000041d9c3 in itemview::mousepressevent (this=0x2e31db0, mevent=0x0) @ src/qt/views/itemview.cpp:66 #11 0x00007ffff5c8a4a1 in qwidget::event(qevent*) () /usr/lib/libqtgui.so.4 #12 0x00007ffff5c3b0dc in qapplicationprivate::notify_helper(qobject*, qevent*) () /usr/lib/libqtgui.so.4 #13 0x00007ffff5c417dd in qapplication::notify(qobject*, qevent*) () /usr/lib/libqtgui.so.4 #14 0x00007ffff570bebd in qcoreapplication::notifyinternal(qobject*, qevent*) () /usr/lib/libqtcore.so.4 #15 0x00007ffff5c40f93 in qapplicationprivate::sendmouseevent(qwidget*, qmouseevent*, qwidget*, qwidget*, qwidget**, qpointer<qwidget>&, bool) () /usr/lib/libqtgui.so.4 #16 0x00007ffff5cb2bab in ?? () /usr/lib/libqtgui.so.4 #17 0x00007ffff5cb161c in qapplication::x11processevent(_xevent*) () /usr/lib/libqtgui.so.4 #18 0x00007ffff5cd8162 in ?? () /usr/lib/libqtgui.so.4 #19 0x00007ffff2f4a296 in g_main_context_dispatch () /usr/lib/libglib-2.0.so.0 #20 0x00007ffff2f4a5e8 in ?? () /usr/lib/libglib-2.0.so.0 #21 0x00007ffff2f4a68c in g_main_context_iteration () /usr/lib/libglib-2.0.so.0 #22 0x00007ffff5738b25 in qeventdispatcherglib::processevents(qflags<qeventloop::processeventsflag>) () /usr/lib/libqtcore.so.4 #23 0x00007ffff5cd8216 in ?? () /usr/lib/libqtgui.so.4 #24 0x00007ffff570ab1f in qeventloop::processevents(qflags<qeventloop::processeventsflag>) () /usr/lib/libqtcore.so.4 #25 0x00007ffff570ae15 in qeventloop::exec(qflags<qeventloop::processeventsflag>) () /usr/lib/libqtcore.so.4 #26 0x00007ffff570ff4b in qcoreapplication::exec() () /usr/lib/libqtcore.so.4 #27 0x000000000042b041 in windowmanager::exec (this=this@entry=0x733b90) @ src/qt/windowmanager.cpp:66 #28 0x00000000004401c0 in client::init (this=this@entry=0x729750, ac=ac@entry=1, av=av@entry=0x7fffffffe858) @ src/client.cpp:52 #29 0x0000000000414b04 in main (ac=1, av=0x7fffffffe858) @ src/main.cpp:22
is there way make work in release mode ?
thanks.
data->settext(oss.str().c_str());
will construct new qstring possibly backed by char*
temporary string (ie destructed sure after returning settext). later when program try manipulate string crashes on release (because invalid), may not on debug, because of compiler shenanigans.
rather uses
data->settext(qstring::fromstdstring(oss.str()));
Comments
Post a Comment