Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QT 5.6.1 : App crashes after exiting slot only with x86 dlls but not x64 dlls



  • Hi everybody,

    I hope someone here have already deal with my issue and will be able to help me out :)

    Context :
    I am using QT 5.6.1 compiled dynamically (x86 and x64) on a Windows 10 x64.

    Problem :
    I have made a basic program compiled twice (x86 and x64) that displays a Window with a button and connects the button to the "clicked" signal. My Window is correctly displayed but when i hit my button to fire signal the app crashed just after exiting the SLOT (i have put a qDebug in the slot that is correctly printed). But i am only facing this issue with x86 QT dll's. It works fine with x64 dll's (no crash after leaving the slot).

    The crash appears with the x86 version on the program on a Windows 10 x64, a Windows 7 x86 pc and a Windows 7 x64 as well.

    Here is the call trace

    Qt5Widgets!QAction::activate+0x103
    Qt5Widgets!QToolButton::nextCheckState+0x1a
    Qt5Widgets!QAbstractButton::click+0x103
    Qt5Widgets!QAbstractButton::mouseReleaseEvent+0x7e
    Qt5Widgets!QToolButton::mouseReleaseEvent+0xd
    Qt5Widgets!QWidget::event+0xa8
    Qt5Widgets!QSizePolicy::QSizePolicy+0x83b
    Qt5Core!QCoreApplication::translate+0x30f56
    Qt5Gui!QGuiApplicationPrivate::processMouseEvent+0x6c1
    USER32!SetManipulationInputTarget+0x53
    USER32!DispatchMessageW+0x251
    USER32!DispatchMessageW+0x10
    qwindows!qt_plugin_query_metadata+0x2065
    Qt5Core!QCoreApplication::exec+0x160
    qt_auth_test!wmain+0x7c
    qt_auth_test!QObject::event+0xb5
    KERNEL32!BaseThreadInitThunk+0x24
    ntdll!RtlUnicodeStringToInteger+0x21e
    ntdll!RtlCaptureContext+0xe1
    

    Why does it crashed during the call to "QAction::activate" only with x86 dlls?! Is this an issue with the C-Runtime?

    Here is the code (not sur if it's useful) :

    /* HEADER */
    class MyWidget: public QWidget
    {
        Q_OBJECT;
        public:
            MyWidget();
            virtual ~MyWidget();
        private slots:
            void _onMyActionTriggered(bool bValue);
        private:
    };
    /* SOURCE */
    MyWidget::MyWidget()
    {
        QMainWindow *pqMainWindow= new QMainWindow(this);
        QPushButton *pqButton= new QPushButton("MyButton");
        /* Setting up the window */
        pqMainWindow->setWindowModality(Qt::WindowModal);
        pqMainWindow->setGeometry(geometry());
        pqMainWindow->move(QPoint(100, 100));
        /* Connecting signal clicked to slot */
        QObject::connect(pqButton, SIGNAL(clicked(bool)), this, SLOT(_onMyActionTriggered(bool)));    
        pqMainWindow->setCentralWidget(pqButton);
        /* Showing the window */
        pqMainWindow->show();
    }
    MyWidget::~MyWidget()
    {
        /* Nothing to do yet */
    }
    void MyWidget::_onMyActionTriggered(bool bValue)
    {
        qDebug("Slot <_onMyActionTriggered> called");
    }
    int __cdecl main(int argc, char **argv)
    {
        QApplication qapp(argc, argv);
        MyWidget widget;
        return qapp.exec();
    }
    

    Thank you if you can help.



  • I am not sure if the calling convention in main '__cdecl' has anything to do with the crash. I usually don't specify this for any Qt programs and I believe Win32 uses a different calling convention (__fastcall ?) but I am not sure if this applies to main(). The wrong calling convention will definitely crash the program if this is not set properly.

    The program looks straight forward otherwise. Everything I compile for Windows is x86 (mingw) and I have not had any issues with crashing on any OS (Win XP -> Win10).



  • @Rondog You are absolutely right! Thank you! My program uses the stdcall (/Gz) convention but QT uses cdecl (/Gd). The generated moc file was compiled with the stdcall convention and this is what caused the issue (stack problem when releasing parameters because of different convention between callee and caller).
    Now my program is compiled using the stdcall convention (because it is mandatory for me) BUT the generated moc files are compiled with cdecl and i have set the __cdecl keyword on my private slots headers! It works!
    Tanks a lot!!!


Log in to reply