Results 1 to 2 of 2

Thread: App crashes when moving a DockWidget outside MainWindow

  1. #1
    Join Date
    Aug 2010
    Posts
    17
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Question App crashes when moving a DockWidget outside MainWindow

    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 ?

  2. #2
    Join Date
    Aug 2007
    Posts
    166
    Thanks
    16
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: App crashes when moving a DockWidget outside MainWindow

    QApplication will delete the main window without caring if it is his child or not and I guess that when you delete it yourself when the application object is destructing there is no way for the MainWindow to tell to QApplication that it is deleted and eventually QApplication will try to delete it while looping trough all the objects. So you have 2 choices:

    1. Make sure you delete the MainWindow before the destruction of QApplication
    2. Let QApplication care for that( this can be tricky depending on your program logic ).

Similar Threads

  1. Replies: 0
    Last Post: 24th May 2010, 12:19
  2. Replies: 3
    Last Post: 4th September 2009, 12:49
  3. DockWidget not moving inside QWidget ?
    By aurelius in forum Qt Programming
    Replies: 6
    Last Post: 3rd February 2009, 10:24
  4. Dockwidget and Toolbutton
    By sandeepvl in forum Qt Programming
    Replies: 3
    Last Post: 13th May 2008, 07:23
  5. DockWidget ?
    By allensr in forum Qt Programming
    Replies: 8
    Last Post: 30th January 2007, 23:58

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.