title: Calling width(), height(), size() or rect() inside subclass of QWidget ends with segfault
body: <p>I have a problem with <code>QWidget</code>'s <code>width()</code>, <code>height()</code>, <code>size()</code> or <code>rect()</code> function; when it is called it gets a segfault. It is Qt 4.7.</p>
  
  <p>Here is the header of the problematic class:  </p>
  
  <pre><code>class PlotCanvas : public QWidget
  { 
      void paintEvent(QPaintEvent * e);
      uint64_t smallestDiv();
      uint64_t longestLength();
      void drawGrid(QPainter * painter);
      QVector&lt;Plot*&gt; 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();
  };
  </code></pre>
  
  <p>and actual segfaulting code:   </p>
  
  <pre><code>int PlotCanvas::getDivCount()
  {
     QRect bounds = rect(); //segfaults
     qDebug() &lt;&lt; bounds.size().width();
     qDebug() &lt;&lt; bounds.size().height();
     return 10;
  }
  </code></pre>
  
  <p>traced into Qt's <code>qrect.h</code>:  </p>
  
  <pre><code>inline int QRect::width() const
  { return  x2 - x1 + 1; } //this line finally kills it
  </code></pre>
  
  <p>Which seems like there is something not initialized properly inside <code>QWidget</code>, but I have no clue what, because as you can see I am not really changing initialization of <code>QWidget</code> that much.</p>
  
  <p><code>PlotCanvas</code> widget resides in subclass of <code>QAbstractScrollArea</code> (which is not implemented yet, so it is just plain <code>QAbstractScrollArea</code>:</p>
  
  <pre><code>class PlotCanvasScrollArea : public QAbstractScrollArea
  {
  public:
      PlotCanvasScrollArea(QWidget * parent = 0) : QAbstractScrollArea(parent) 
      {
  
      }
  };
  </code></pre>
  
  <p>I just need to determine size of <code>QWidget</code> painting area, because I am plotting in transition diagram and I need to know how many time divisions will fit into current widget size, because obviously application window is resizable.</p>
  
  <p>EDIT:  </p>
  
  <p>Code where <code>PlotCanvas</code> is constructed:  </p>
  
  <pre><code>Board(QString &amp; name) : name(name)
  {
      hbox = new QHBoxLayout();
      commonKnobGroup = new QGroupBox("Common settings:");
      commonKnobGroup-&gt;setMinimumWidth(190);
      commonKnobGroup-&gt;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-&gt;addWidget(plotSplitter);
      plotGroupBox-&gt;setLayout(plotHbox);
      settingsVLayout = new QVBoxLayout();
      plotNamesColumn = new QListWidget(plotSplitter);
      scrollArea = new PlotCanvasScrollArea(plotSplitter);
      //scrollArea-&gt;setWidgetResizable(true);
      plotsCanvas = new PlotCanvas();
      scrollArea-&gt;setViewport(plotsCanvas);
      scrollArea-&gt;setBackgroundRole(QPalette::Dark);
      specializedKnobGroup = new QGroupBox("Probe settings:");
      plotSettings = new QStackedWidget(specializedKnobGroup);
      settingsVLayout-&gt;addWidget(commonKnobGroup);
      settingsVLayout-&gt;addWidget(specializedKnobGroup);
      settingsGroupBox-&gt;setLayout(settingsVLayout);
      hbox-&gt;addWidget(hsplitter);
      setLayout(hbox);
      connect(plotNamesColumn, SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)), this,
              SLOT(changePageNames(QListWidgetItem*, QListWidgetItem*)));
      connect(commonKnobs, SIGNAL(scaleUpdated()), plotsCanvas, SLOT(update()));
  
  };
  </code></pre>
  
  <p>EDIT2:<br>
  Complete stacktrace:</p>
  
  <pre><code>#0  0x000000010000b9ac in QWidget::rect() const at /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&amp;) ()
  #8  0x000000010043b321 in QAbstractSpinBoxPrivate::setValue(QVariant const&amp;, EmitPolicy, bool) ()
  #9  0x000000010043c11a in QAbstractSpinBoxPrivate::_q_editorTextChanged(QString const&amp;) ()
  #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&amp;) ()
  #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&amp;) ()
  #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&lt;Qt::KeyboardModifier&gt;, QString const&amp;, 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&lt;QEventLoop::ProcessEventsFlag&gt;) ()
  #40 0x0000000100def774 in QEventLoop::processEvents(QFlags&lt;QEventLoop::ProcessEventsFlag&gt;) ()
  #41 0x0000000100defa94 in QEventLoop::exec(QFlags&lt;QEventLoop::ProcessEventsFlag&gt;) ()
  #42 0x0000000100df10bc in QCoreApplication::exec() ()
  #43 0x0000000100001cf6 in main ()
  </code></pre>