(更新)QT QML 5.6 - 什么原因导致此警告"QApplication was not created in the main() thread"?



[UPDATE]好的,我正在更新我之前的问题。起初,我以为从.pro文件中删除widgets时会弹出警告——这可能是一种特殊的行为。在深入研究之后,我得到了一个完全空的应用程序,问题仍然存在。我的应用程序如下:

#include <QApplication>
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    return app.exec();
}    

基于其他有类似问题的帖子,我了解到QApplication需要是第一个初始化的东西。在这种情况下,应用程序中没有其他内容。这个警告怎么还在冒出来?

W/ (16992): (null):0 ((null)): WARNING: QApplication was not created in the main() thread.

我使用Android for x86 (GCC 4.9, Qt 5.6.0)工具包直接在我的Android设备上编译应用程序。

----老问题\开始----

目前正在开发基于Qt 5.6(C++和QML(的Android应用程序。由于UI是基于QtQuick的,我从pro.file.中删除了"小部件">

QT += core qml quick widgets network svg xml gui    

这导致了警告:

WARNING: QApplication was not created in the main() thread.    

而且。。。一旦我在main((中实例化QQmlEngine(当然是在创建QApplication之后(,就会显示此警告:

 QObject: Cannot create children for a parent that is in a different thread.
(Parent is QQmlDebuggerServiceFactory(0x65fffcd0), parent's thread is QThread(0x5d449f10), current thread is QThread(0x65183000)    

显然,应用程序在另一个线程中启动?和main((在另一个中?当我在.pro文件中放入"widgets"时,这两个错误就不再显示了。我真的不明白这两件事之间的关系P.S.在程序的这个阶段并不真正相关,但我也没有在我的应用程序中创建任何新线程这就是我的main((的样子:

int main(int argc, char *argv[])
{
   QApplication app(argc, argv);
   qmlRegisterUncreatableType<MainFrame>("PSGApp", 1, 0, "MainFrame", "");
   MainFrame m_MainFrame;
   QQmlEngine engine;
   engine.rootContext()->setContextProperty("q_MainFrame",             &m_MainFrame);
   engine.rootContext()->setContextProperty("Ctr",                     m_MainFrame.c());
   engine.rootContext()->setContextProperty("Dev",                     m_MainFrame.c()->dev());
   engine.rootContext()->setContextProperty("Def",                     m_MainFrame.c()->dev()->_def());
   engine.rootContext()->setContextProperty("ModelUdpDevices",         m_MainFrame.UdpDevices());
   engine.rootContext()->setContextProperty("ModelDashboardDevices",   m_MainFrame.DashboardDevices());
   engine.rootContext()->setContextProperty("ModelZones",              m_MainFrame.c()->dev()->_DevZones());
   engine.rootContext()->setContextProperty("ModelRGParameter",        m_MainFrame.c()->dev()->RegelParameter());
   engine.rootContext()->setContextProperty("ModelSYSParameter",       m_MainFrame.c()->dev()->SysParameter());
   engine.rootContext()->setContextProperty("ModelKOMMParameter",      m_MainFrame.c()->dev()->KommParameter());
   QObject::connect(&app, SIGNAL(applicationStateChanged(Qt::ApplicationState)), &m_MainFrame, SLOT(applicationStateChanged(Qt::ApplicationState)));
   QObject::connect(&engine, SIGNAL(quit()), &app, SLOT(quit()));
   QQmlComponent component(&engine,QUrl(QStringLiteral("qrc:/qml/main.qml")));
   component.create();
   return app.exec();
}    

----老问题\结束----

QApplication依赖于widgets模块。请改用QGuiApplication

发现错误。项目中仍然包含一个未使用的文件(尽管代码中没有#includeed(,并且它有一个QTranslator的全局实例。从各种其他(类似(线程可以清楚地看出,QApplication应该是在main()中初始化的第一个QObject。这就是main()不在父线程中的原因,因为QTranslator是在执行main()之前初始化的。

这样一个愚蠢的错误花了整整一天的时间。和平

相关内容

最新更新