qml程序如果存在c++后台线程,那么在关闭qml主窗口时,必须先清理后台线程资源,并退出后台线程之后,才能正常退出程序。否则会报错:QThread: Destroyed while thread is still running
以下是代码:
int main(int argc, char *argv[])
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
//QGuiApplication app(argc, argv);
QApplication app(argc, argv);
app.setWindowIcon(QIcon(":/app.png"));
//MainBackgroundProcess
QThread threadProcess;
MainBackgroundProcess::instance()->moveToThread(&threadProcess);
QObject::connect(&threadProcess, &QThread::started, [=](){
MainBackgroundProcess::instance()->init();
});
threadProcess.start();