[更新]好的,我正在更新我以前的問題。起初,我認爲當我從.pro文件中刪除widgets
時會彈出警告 - 這將是一種奇怪的行爲。深入挖掘後,我最終得到了一個完全空白的應用程序,問題仍然存在。我的應用程序是這樣的:(更新)QT QML 5.6 - 導致此警告的原因「QApplication未在main()線程中創建」?
#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.
也......只要我實例QQmlEngine在main()這個警告也顯示(當然創造的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文件中,這兩個錯誤都不會再顯示出來。我真的不知道這兩件事之間的關係。 P.S.在程序的這個階段沒有真正的相關性,但我也沒有在我的應用程序中創建任何新線程。 這就是我的主要()看起來像:
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();
}
----老問題\結束----
我已經更新了這個問題。問題不是.pro文件中的「widgets」模塊。即使應用程序完全空白,問題仍然存在。檢查編輯的問題。爲什麼不在main()線程中創建QApplication,即使沒有別的東西? – spikeyeddy