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)- how to write try catch in the slotShowMsgbox(), in order to take care of stack overflow;
- is there any way to avoid stackoverflow? should i new QMessagebox? and how to delete it?
-
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. -
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 ? -
@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();