Solved Why crash in QDialog::close()
-
void func() { QMetaObject::invokeMethod(qApp, [this] { pLoading->close(); pLoading = NULL; pMainWindow->show(); }); }
My Qcoreapplication was created and Run in a Secondary Thread. pLoading(QDialog) and pMainWindow also created and be used in the same thread as GUI Class.
This func() above was called in the main thread, it performed well in my computer.
But when I look into others' dumper, I find someone (2% people) crash whenpLoading->close();
(Qt5Widgets.dll!QWidgetPrivate::close_helper(QWidgetPrivate::CloseMode mode)
)What are the possible reasons.
-
Hi,
There's no check that pLoading is a valid pointer.
Nothing in that code shows that it's is run in the correct thread therefore you might be just lucky that it runs 98% of the time.
-
@SGaist Thanks for your reply.
bRetCode = QMetaObject::invokeMethod(qApp, [this] { pMainWindow = new KMainWindowNew(NULL); pLoading = new KLoading(NULL); }, Qt::BlockingQueuedConnection);
I think this code make sure pLoading is created in the correct thread, and it will exec() by the same way.
Maybe pLoading was closed by people, sono check that pLoading
make the application crashed? -
@Toocold said in Why crash in QDialog::close():
so no check that pLoading make the application crashed?
Use QPointer<> and check for != nullptr before calling close()
-
@Christian-Ehrlicher said in Why crash in QDialog::close():
@Toocold said in Why crash in QDialog::close():
so no check that pLoading make the application crashed?
Use QPointer<> and check for != nullptr before calling close()
okay