As far as I understand you need 3 different objects (it can be instances of appropriate class or its subclass) for pattern to work:
1. QMainWindow ( add dock widget to) 2. QDockWidget 3. QWidget ( widget for setWidget which would be displayed by QDockWidget ) And 3 is missing in > void QScaffy::addView(View *view) Hope this helps. Alex On Mon, Jul 30, 2012 at 9:03 AM, Rollastre Prostrit <rollas...@gmail.com> wrote: > Hello list. > > I'm in kubuntu 12.04 with Qt 4.8.1. > > I have a class called View which is a subclass of QDockWidget. In its > constructor I do this > > View::View(QWidget* parent = NULL) > : QDockWidget(MainWindow::Instance()) > { > setFeatures(QDockWidget::DockWidgetClosable | > QDockWidget::DockWidgetMovable); > } > > > > > if I use the following method to add a view to the main window > > void QScaffy::addView(View *view) > { > view->setParent(w); > > qDebug() << "adding view " << view->getViewTitle(); > view->setWindowTitle(view->getViewTitle()); > w->addDockWidget(Qt::LeftDockWidgetArea, view, Qt::Horizontal); // > where w is a MainWindow (subclass of QMainWindow) > } > > my question is: what am I doing wrong to get a 'segmentation fault' in > qdockwidget.cpp:414? > > int QDockWidgetLayout::minimumTitleWidth() const > { > QDockWidget *q = qobject_cast<QDockWidget*>(parentWidget()); > <---------------- this returns a QWidget and upon the cast q points to 0x0 > > if (QWidget *title = widgetForRole(TitleBar)) > return pick(verticalTitleBar, title->minimumSizeHint()); > > QSize closeSize(0, 0); > QSize floatSize(0, 0); > if (hasFeature(q, QDockWidget::DockWidgetClosable)) { > <------------------------------------- Crash HERE > if (QLayoutItem *item = item_list[CloseButton]) > closeSize = item->widget()->sizeHint(); > } > if (hasFeature(q, QDockWidget::DockWidgetFloatable)) { > if (QLayoutItem *item = item_list[FloatButton]) > floatSize = item->widget()->sizeHint(); > } > > int titleHeight = this->titleHeight(); > > int mw = q->style()->pixelMetric(QStyle::PM_DockWidgetTitleMargin, > 0, q); > int fw = q->style()->pixelMetric(QStyle::PM_DockWidgetFrameWidth, > 0, q); > > return pick(verticalTitleBar, closeSize) > + pick(verticalTitleBar, floatSize) > + titleHeight + 2*fw + 3*mw; > } > > > > However, if my View is just a plain Widget and I manually create a > QDockWidget like this it works > > void QScaffy::addView(QWidget *view) > { > QDockWidget *dock = new QDockWidget(tr("New"), w); > dock->setFeatures(QDockWidget::DockWidgetClosable | > QDockWidget::DockWidgetMovable); > dock->setWidget(view); > > w->addDockWidget(Qt::LeftDockWidgetArea, dock, Qt::Horizontal); > > } > > > > Do you have any clue what is going on here? > > Thanks in advance. > _______________________________________________ > Interest mailing list > Interest@qt-project.org > http://lists.qt-project.org/mailman/listinfo/interest _______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest