Application crash with ASSERT error
-
I have this error when closing the application, but I am not using QCoreApplication, QChart or Qml. Could you tell me any possible solution?
ASSERT: "!"No style available without QApplication!"" in file kernel\qapplication.cpp, line 1038 | kernel\qapplication.cpp:1038
-
-
@ChrisW67
The code is too long, but I am using Qt 5.12 on Windows 10, and the error began when I upgraded the code from Qt 4.7 to Qt 5, before that, it worked fine.Thanks for answering
@danymt
The error message tells you that you are trying to use some "style" but have not created aQApplication
instance yet, at least at the instant the style code is being hit. You need to create that in a Qt UI program. I cannot say why it did work prior to Qt5.You can see the error at https://code.woboq.org/qt5/qtbase/src/widgets/kernel/qapplication.cpp.html#1037, which looks like:
/*! Returns the application's style object. \sa setStyle(), QStyle */ QStyle *QApplication::style() { if (QApplicationPrivate::app_style) return QApplicationPrivate::app_style; if (!qobject_cast<QApplication *>(QCoreApplication::instance())) { Q_ASSERT(!"No style available without QApplication!"); return 0; }
-
I already found the problem.
I was using an object:QApplication app(argc, argv);
instead of a pointer:QApplication* app = new QApplication(argc, argv);
Using the pointer, everything worked fine.
Thank you all.@danymt
That is actually a bit worrying, asQApplication app(argc, argv);
should be fine and is in fact the way you will see in most examples. The question is: where do you put this? It should be inmain()
, so scope/lifetime will be fine. Do/did you have it elsewhere, so that it went out of scope?