[更新]好的,我正在更新我的上一个问题。最初,我认为当我widgets
从.pro文件中删除时会弹出警告-这本来是奇怪的行为。深入研究之后,我得到了一个完全空的应用程序,问题仍然存在。我的应用程序如下所示:
#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()在另一个?一旦我将.widgets放入.pro文件中,两个错误均不再显示。我并没有真正了解这两件事之间的相关性。PS在程序的此阶段并不真正相关,但是我也没有在我的应用程序中创建任何新线程。这是我的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();
}
----旧问题\结束----
发现了错误。一个未使用的文件仍包含在项目中(即使未#include
在代码中进行编辑),并且具有的全局实例QTranslator
。从其他各种(类似)线程可以明显看出,QApplication
应该首先QObject
在中初始化main()
。这就是为什么main()
不在父线程中的原因,因为它QTranslator
是在执行之前初始化的main()
。
这样一个愚蠢的错误花了整整一天的时间。和平!
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句