c++ - Calling width(), height(), size() or rect() inside subclass of QWidget ends with segfault -


i have problem qwidget's width(), height(), size() or rect() function; when called gets segfault. qt 4.7.

here header of problematic class:

class plotcanvas : public qwidget { void paintevent(qpaintevent * e); uint64_t smallestdiv(); uint64_t longestlength(); void drawgrid(qpainter * painter); qvector<plot*> plots; int calculateheight() const; int calculatewidth() const; uint32_t cursorposition; public: plotcanvas(qwidget * parent = 0) : qwidget(parent) { setstylesheet("background-color: black"); setautofillbackground(true); setsizepolicy(qsizepolicy::minimumexpanding, qsizepolicy::minimumexpanding); setfocuspolicy(qt::strongfocus); update(); } void addplot(plot * plot); int getdivcount(); }; 

and actual segfaulting code:

int plotcanvas::getdivcount() { qrect bounds = rect(); //segfaults qdebug() << bounds.size().width(); qdebug() << bounds.size().height(); return 10; } 

traced qt's qrect.h:

inline int qrect::width() const { return x2 - x1 + 1; } //this line kills 

which seems there not initialized inside qwidget, have no clue what, because can see not changing initialization of qwidget much.

plotcanvas widget resides in subclass of qabstractscrollarea (which not implemented yet, plain qabstractscrollarea:

class plotcanvasscrollarea : public qabstractscrollarea { public: plotcanvasscrollarea(qwidget * parent = 0) : qabstractscrollarea(parent) { } }; 

i need determine size of qwidget painting area, because plotting in transition diagram , need know how many time divisions fit current widget size, because application window resizable.

edit:

code plotcanvas constructed:

board(qstring & name) : name(name) { hbox = new qhboxlayout(); commonknobgroup = new qgroupbox("common settings:"); commonknobgroup->setminimumwidth(190); commonknobgroup->setsizepolicy(qsizepolicy(qsizepolicy::minimum, qsizepolicy::minimum)); commonknobs = new commonknobs(commonknobgroup); hsplitter = new qsplitter(); plotgroupbox = new qgroupbox("measurement plots:", hsplitter); settingsgroupbox = new qgroupbox("plot settings:", hsplitter); plotsplitter = new qsplitter(); plothbox = new qhboxlayout(); plothbox->addwidget(plotsplitter); plotgroupbox->setlayout(plothbox); settingsvlayout = new qvboxlayout(); plotnamescolumn = new qlistwidget(plotsplitter); scrollarea = new plotcanvasscrollarea(plotsplitter); //scrollarea->setwidgetresizable(true); plotscanvas = new plotcanvas(); scrollarea->setviewport(plotscanvas); scrollarea->setbackgroundrole(qpalette::dark); specializedknobgroup = new qgroupbox("probe settings:"); plotsettings = new qstackedwidget(specializedknobgroup); settingsvlayout->addwidget(commonknobgroup); settingsvlayout->addwidget(specializedknobgroup); settingsgroupbox->setlayout(settingsvlayout); hbox->addwidget(hsplitter); setlayout(hbox); connect(plotnamescolumn, signal(currentitemchanged(qlistwidgetitem *, qlistwidgetitem *)), this, slot(changepagenames(qlistwidgetitem*, qlistwidgetitem*))); connect(commonknobs, signal(scaleupdated()), plotscanvas, slot(update())); }; 

edit2:
complete stacktrace:

#0 0x000000010000b9ac in qwidget::rect() const @ /volumes/data/shinji/qtsdk/desktop/qt/474/gcc/include/qtgui/qwidget.h:1007 #1 0x000000010000b454 in plotcanvas::getdivcount() () #2 0x000000010000ab39 in board::getdivcount() () #3 0x0000000100009fbc in commonknobs::updatescalebybeginend() () #4 0x00000001000015b4 in commonknobs::qt_metacall(qmetaobject::call, int, void**) () #5 0x0000000100d09b66 in qmetaobject::activate(qobject*, qmetaobject const*, int, void**) () #6 0x000000010070df9d in qspinbox::valuechanged(int) () #7 0x00000001004d9684 in qspinboxprivate::emitsignals(emitpolicy, qvariant const&) () #8 0x000000010043b321 in qabstractspinboxprivate::setvalue(qvariant const&, emitpolicy, bool) () #9 0x000000010043c11a in qabstractspinboxprivate::_q_editortextchanged(qstring const&) () #10 0x000000010043cca7 in qabstractspinbox::qt_metacall(qmetaobject::call, int, void**) () #11 0x000000010070e435 in qspinbox::qt_metacall(qmetaobject::call, int, void**) () #12 0x0000000100d09b66 in qmetaobject::activate(qobject*, qmetaobject const*, int, void**) () #13 0x000000010048a1e6 in qlineedit::textchanged(qstring const&) () #14 0x000000010048d23a in qlineedit::qt_metacall(qmetaobject::call, int, void**) () #15 0x0000000100d09b66 in qmetaobject::activate(qobject*, qmetaobject const*, int, void**) () #16 0x000000010070c9f9 in qlinecontrol::textchanged(qstring const&) () #17 0x0000000100494337 in qlinecontrol::finishchange(int, bool, bool) () #18 0x0000000100496664 in qlinecontrol::processkeyevent(qkeyevent*) () #19 0x000000010048b8eb in qlineedit::keypressevent(qkeyevent*) () #20 0x00000001001056bd in qwidget::event(qevent*) () #21 0x000000010048c18b in qlineedit::event(qevent*) () #22 0x000000010043d9f0 in qabstractspinbox::keypressevent(qkeyevent*) () #23 0x00000001001056bd in qwidget::event(qevent*) () #24 0x000000010043bb1b in qabstractspinbox::event(qevent*) () #25 0x00000001004d7be5 in qspinbox::event(qevent*) () #26 0x00000001000a9e8d in qapplicationprivate::notify_helper(qobject*, qevent*) () #27 0x00000001000b198b in qapplication::notify(qobject*, qevent*) () #28 0x0000000100d0321c in qcoreapplication::notifyinternal(qobject*, qevent*) () #29 0x00000001000a9f2c in qt_sendspontaneousevent(qobject*, qevent*) () #30 0x0000000100125cc1 in qkeymapper::sendkeyevent(qwidget*, bool, qevent::type, int, qflags<qt::keyboardmodifier>, qstring const&, bool, int, unsigned int, unsigned int, unsigned int, bool*) () #31 0x0000000100126b43 in qkeymapperprivate::translatekeyevent(qwidget*, opaqueeventhandlercallref*, opaqueeventref*, void*, bool) () #32 0x000000010006072e in qt_dispatchkeyevent(void*, qwidget*) () #33 0x000000010005478b in -[qcocoaview keydown:] () #34 0x00007fff815a90c7 in -[nswindow sendevent:] () #35 0x0000000100059891 in -[qcocoawindow sendevent:] () #36 0x00007fff814ddafa in -[nsapplication sendevent:] () #37 0x000000010005cf0a in -[qnsapplication sendevent:] () #38 0x00007fff814746de in -[nsapplication run] () #39 0x0000000100066c04 in qeventdispatchermac::processevents(qflags<qeventloop::processeventsflag>) () #40 0x0000000100def774 in qeventloop::processevents(qflags<qeventloop::processeventsflag>) () #41 0x0000000100defa94 in qeventloop::exec(qflags<qeventloop::processeventsflag>) () #42 0x0000000100df10bc in qcoreapplication::exec() () #43 0x0000000100001cf6 in main () 

look @ crash stack trace - lead constructor somewhere? first thought i'm not sure should calling update inside constructor - off base, seems wrong me. if update should called inside qwidget constructor, base constructor call (making call redundant), , if shouldn't, i'm not @ clear what's going happen.


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -