I am developing a GUI application, but whenever I am trying to close the application, it throws an error that "Must construct QGuiapplication first". My main is not returning exit code 0, so it's not exiting normally. I think some destructor is getting called twice but need some help here. I am attaching main.cpp code here for reference.
#include <QGuiApplication>
#include <QFontDatabase>
#include <QtWebEngine>
#include "ApplicationManager.h"
#include "AppLogger.h"
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QCoreApplication::setAttribute(Qt::AA_UseOpenGLES);
QGuiApplication app(argc, argv);
QtWebEngine::initialize();
app.setApplicationName("MCS3.0");
QFontDatabase::addApplicationFont(":/Fonts/Roboto.ttf");
#ifdef VERSION
app.setApplicationVersion(QString("%1").arg(VERSION));
logInfoMessage(app.applicationName()+app.applicationVersion()+" Started");
#endif
ApplicationManager::instance().run();
return app.exec();
}
The relevant part of the problem is inside
ApplicationManager.h
which was not exposed by OP.I bet that it makes another instance of
QApplication
(orQGUIApplication
orQCoreApplication
).How can I know this? It's partly a guess (as the name looks like) and partly result of the following test:
testQApp.cc
:testQApp.pro
:Compiled and tested in cygwin64 on Windows 10:
When I quit the application, the issue occurs:
To make this complete, the relevant paragraph of doc. about
QApplication
:Please, note that the emphasize is not done by me.