Hi There, I have got an application that always crashes when having moved a dockwidget outside the mainwindow. When I leave the dockwidget at its iriginal Place on the left docking area the application will close fine.


App ist build up with this code (Control will instantiate and destroy mainwindow):

Qt Code:
  1. int main(int argc, char *argv[])
  2. {
  3. QApplication app(argc, argv);
  4.  
  5. // app will destroy Control
  6. // because it becomes Control's
  7. // parent object via constructur
  8. Control::getSingleton(&app);
  9. int ret = app.exec();
  10.  
  11. return ret;
  12. } // app Object will be destroyed (and its children)
To copy to clipboard, switch view to plain text mode 

IMHO the ~Control() Destructor will be called by the Application at last, so when finishing the application there will be (the destr. ist definitively called):

Qt Code:
  1. /* singleton-private Constructor */
  2. Control::Control(QObject *parent) :
  3. QObject(parent),
  4. {
  5. ...
  6. if(!mainWindow)
  7. mainWindow = new MainWindow();
  8. ...
  9. }
  10.  
  11. Control::~Control()
  12. {
  13. ...
  14. if(mainWindow) {
  15. delete mainWindow; // will delete the ui including dockwidgets
  16. mainWindow = NULL;
  17. }
  18. }
To copy to clipboard, switch view to plain text mode 

The Problem now is that when I have App destroying the mainwindow there comes a segmentation fault along - ending always in qwidget.cpp...

Qt Code:
  1. ....
  2. else if (!internalWinId() && isVisible()) {
  3. qApp->d_func()->sendSyntheticEnterLeave(this);
  4. ....
To copy to clipboard, switch view to plain text mode 

...where the d_func() with its scoped pointer will fail.

But: This only happens, when I have moved the DockWidet "Floating" away from its orignial Place in the main window. If I leave it there, everthing is ok.

As someone may see the stacktrace shows that the Dockwidget will make use of the qapplication d_func(). Am I wrong, or why do at least two parents try to delete the Widget (Mainwindow and App) ?

Qt Code:
  1. 0 QScopedPointer<QObjectData, QScopedPointerDeleter<QObjectData> >::data qscopedpointer.h 135 0x00ff01e6
  2. 1 qGetPtrHelper<QScopedPointer<QObjectData, QScopedPointerDeleter<QObjectData> > > qglobal.h 2314 0x008a63ff
  3. 2 QApplication::d_func qapplication.h 376 0x00eef9c4
  4. 3 ~QWidget qwidget.cpp 1438 0x008ec5f8
  5. 4 ~QDockWidget qdockwidget.cpp 1181 0x00c51fce
  6. 5 QObjectPrivate::deleteChildren qobject.cpp 1978 0x6a20f1b0
  7. 6 ~QWidget qwidget.cpp 1476 0x008ec6dc
  8. 7 ~QMainWindow qmainwindow.cpp 329 0x00c82888
  9. 8 ~MainWindow mainwindow.cpp 50 0x004018c0
  10. 9 ~Control control.cpp 83 0x00408feb
  11. 10 QObjectPrivate::deleteChildren qobject.cpp 1978 0x6a20f1b0
  12. 11 ~QObject qobject.cpp 975 0x6a20d0f9
  13. 12 ~QCoreApplication qcoreapplication.cpp 642 0x6a1fd127
  14. 13 ~QApplication qapplication.cpp 1118 0x008aa05e
  15. 14 qMain main.cpp 14 0x00401400
  16. 15 WinMain@16 qtmain_win.cpp 131 0x0040e612
  17. 16 main 0 0x0040e338
To copy to clipboard, switch view to plain text mode 

Any Comments ?