[Interest] Android: WARNING: QApplication was not created in the main() thread.

maitai maitai at virtual-winds.org
Mon Dec 5 22:54:31 CET 2016


I had my main like that:
QMap<QString, QString> folderMap;
int main(int argc, char *argv[])
{
     QApplication *app = new QApplication(argc, argv);
.....
}
and I had folderMap defined as external in other classes when needed

I was getting the warning in that case.

Now I have:
QMap<QString, QString> *folderMap;
int main(int argc, char *argv[])
{
     QApplication *app = new QApplication(argc, argv);
     folderMap = new QMap<QString, QString>;
.....
}
and of course I changed the external definitions accordingly, etc.

Warning is gone in that case, all good, I prefer it that way.

I am just wondering why creating a 'simple' QMap (or QString, whatever) 
in the same main() forces qApp to be created in another thread. You can 
create whatever double, int, bool, or more, no problem. But not 
QObjects. I have been contemplating this warning for the last 2 years 
without a clue about why it occurs, not easy to guess.

Anyway it's gone... I still don't see any differences, but it does look 
better without the warning ;)

Philippe.


Le 05-12-2016 21:44, Thiago Macieira a écrit :
> Em segunda-feira, 5 de dezembro de 2016, às 14:27:01 PST, maitai 
> escreveu:
>> Hello,
>> Can you explain what is the bad thing about having this message?
> 
> It's a warning from Qt. That should be enough reason. ALL Qt warnings 
> are bugs
> in your application. You should develop with QT_FATAL_WARNINGS set to 1 
> and fix
> all warnings you get.
> 
> I will not speculate how bad this particular one might be. You've been
> properly warned that it is bad. You can continue at your own risk 
> (read: we
> won't help you until you fix this).
> 
>> BTW I had this message since a long time, since this thread I have
>> removed some global QObject declarations in my main, and the message 
>> is
>> gone. But it's not clear to me if it's any better and why.
> 
> Global constructors creating QObjects mean that your *real* main() 
> thread is
> the Qt main thread. It's usually not a problem to have them, though I 
> advise
> against.
> 
> The problem is if you create QGuiApplication in another thread.



More information about the Interest mailing list