0

[UPDATE] OK, I am updating my previous question. At first I thought the warning pops up when I remove widgets from the .pro file - which would have been peculiar behavior. After digging down, I ended up with a completely empty application and the problem still persists. My application looks like this:

#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    return app.exec();
}    

Based on other posts with the similar kind of problem, I learnt that QApplicationneeds to be the first thing to be initialized. In this case there is NOTHING else in the application. How is this warning still popping up?

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

I am compiling the application directly on my Android device using the Android for x86 (GCC 4.9, Qt 5.6.0) kit.

---- OLD QUESTION\Start ----

Currently developing an Android app based on Qt 5.6 (C++ and QML). As the UI is based on QtQuick, I removed 'widgets' from the pro.file.

QT += core qml quick widgets network svg xml gui    

this lead to the warning:

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

and also... as soon as i instantiate QQmlEngine in main() (of course after creating QApplication) this warning is also shown:

 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)    

Apparently, the application starts in another thread? and main() in another? as soon as I put 'widgets' in the .pro file, both errors did not show up anymore. I dont really get the correlation between the two things. P.S. not really relevant at this stage of the program but i am also not creating any new threads in my application. This is how my main() looks like:

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();
}    

---- OLD QUESTION\End ----

spikeyeddy
  • 11
  • 4

2 Answers2

0

QApplication depends on the widgets module. Use QGuiApplication instead.

Velkan
  • 7,067
  • 6
  • 43
  • 87
  • I have updated the question. The problem was not the `widgets` module in the .pro file. The problem persists even if the application is completely empty. Check the edited question. Why is the QApplication not created in the main() thread even though there is nothing else? – spikeyeddy Sep 15 '16 at 07:11
0

found the bug. An unused file was still included in the project (even though not #includeed in the code) and it had a global instance of QTranslator. As it is clear from various other (similar) threads, QApplication should be the first QObject to be initialized in main(). Thats why main() was not in the parent thread because QTranslator was initialized before the execution of main().

Such a silly mistake took up an entire day. Peace!

Peter Petrik
  • 9,701
  • 5
  • 41
  • 65
spikeyeddy
  • 11
  • 4