[solved] QScopedPointer crashes application at exit

  • My question why (look at the topic)?

    Here is call stack:
    Qt5Widgetsd.dll!QScopedPointer<QObjectData,QScopedPointerDeleter<QObjectData> >::data() Line 132 C++
    Qt5Widgetsd.dll!qGetPtrHelper<QScopedPointer<QObjectData,QScopedPointerDeleter<QObjectData> > >(const QScopedPointer<QObjectData,QScopedPointerDeleter<QObjectData> > & p) Line 886 C++
    Qt5Widgetsd.dll!QApplication::d_func() Line 222 C++
    Qt5Widgetsd.dll!QWidget::~QWidget() Line 1432 C++
    Qt5Widgetsd.dll!QMainWindow::~QMainWindow() Line 379 C++
    test.exe!MainWindow::~MainWindow() Line 36 C++
    test.exe!MainWindow::instance'::2'::`dynamic atexit destructor for 'inst''() C++
    msvcr110d.dll!doexit(int code, int quick, int retcaller) Line 585 C
    msvcr110d.dll!exit(int code) Line 395 C
    test.exe!__tmainCRTStartup() Line 549 C
    test.exe!mainCRTStartup() Line 377 C
    kernel32.dll!76f9336a() Unknown
    [Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]
    ntdll.dll!77d49f72() Unknown
    ntdll.dll!77d49f45() Unknown

    Here is simple code that reproduce this problem:

    #include <QApplication>
    #include <QMainWindow>
    #include <QWidget>
    #include <QScopedPointer>
    #include <QMenuBar>
    #include <QMenu>

    class MainWindowPrivate {
    : m_widget( 0 )

    QWidget * m_widget;

    class MainWindow
    : public QMainWindow

    MainWindow( QWidget * parent = 0, Qt::WindowFlags f = 0 )
    : QMainWindow( parent, f )
    , d( new MainWindowPrivate )


    static MainWindow & instance()
    static MainWindow inst;

    return inst;

    void init()
    QMenu * fileMenu = menuBar()->addMenu( tr( "&File" ) );

    fileMenu->addAction( QIcon(),
    tr( "E&xit" ), qApp, SLOT( quit() ),
    QKeySequence( tr( "Ctrl+Q" ) ) );

    d->m_widget = new QWidget( this );

    setCentralWidget( d->m_widget );

    Q_DISABLE_COPY( MainWindow )

    QScopedPointer< MainWindowPrivate > d;

    int main( int argc, char ** argv )
    QApplication app( argc, argv );


    return app.exec();

    #include "main.moc"

  • I have same issue
    Probably, you have to file a bug on bug tracker

  • No, it's is not a bug. The problem is that that MainWindow's lifetime more than QApplication. That is why! Thanks to all who helped me in this question.

  • Moderators

    This is not a bug!

    Checkout "setCentralWidget":http://qt-project.org/doc/qt-5.0/qtwidgets/qmainwindow.html#setCentralWidget documentation which clearly states
    Note: QMainWindow takes ownership of the widget pointer and deletes it at the appropriate time.
    Therefore, you should not resume the handling on your side.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.