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

stack overflow when pop many QMessagebox in slot in mainthread, while emit the signalShowMsgbox in another thread



  • stack overflow when pop many QMessagebox in slot in mainthread, while emit the signalShowMsgbox in another thread.
    (unhandled exception at 0x...(Qt5Guid.dll) in my.exe)

    1. how to write try catch in the slotShowMsgbox(), in order to take care of stack overflow;
    2. is there any way to avoid stackoverflow? should i new QMessagebox? and how to delete it?

  • Moderators

    You need to show us the code, otherwise we can only guess. The connection, signal emission and the slot.



  • void signalShowMsgbox(const QString&, const QString&);
    void slotShowMsgbox(const QString& title, const QString&text)
    {
    QMessageBox::critical(NULL, title, text);
    }
    connect signal & slot use Qt::AutoConnection;
    the signal is emitted in not-mainThread;
    slot is in mainThread because Qt ui(messagebox) must be in MainThread.


  • Moderators

    Set the connection to Qt::QueuedConnection explicitly. It probably won't help, but is worth a try.

    By "many" you mean how many messages do you pop up, actually? Perhaps it would be a good idea to rethink that design and group some messages together? Having to close many popups can be annoying to your users.



  • well, the count is not certain, may be 30, 40, or even more...depends on the users transactions.
    yes, ur advice is good, i should not pop up so many Msgbox continuelly in a short time.
    However, as for now, what should i do to avoid Crash when met this stackoverflow?
    can i catch this exception(@Qt5Guid.dll), and just ignore it ?


  • Lifetime Qt Champion

    @opengpu2 Did you use Qt::QueuedConnection as suggested by @sierdzio ?



  • while signal and slot are no in the same thread, isn't AutoConn==QueuedConn??


  • Moderators

    @opengpu2 said in stack overflow when pop many QMessagebox in slot in mainthread, while emit the signalShowMsgbox in another thread:

    while signal and slot are no in the same thread, isn't AutoConn==QueuedConn??

    It should be. It does not hurt to make it explicit, though.

    can i catch this exception(@Qt5Guid.dll), and just ignore it ?

    Qt does not throw any exceptions, so it is rather something "deeper". You can try if you want, but ignoring a stack overflow seems like a bad idea.

    Try using heap instead, like you suggested. Example pseudo-code:

    auto msg = new QMessageBox(this);
    msg->setTitle(title);
    msg->setText(text);
    connect (msg, &QMessageBox::finished, msg, &QMessageBox::deleteLater);
    msg->exec();
    


  • thank you very much!


Log in to reply