[Qt-interest] query on QCoreApplication:exec()
Prasanta Sadhukhan
Prasanta.Sadhukhan at Sun.COM
Tue Dec 2 12:36:59 CET 2008
Prasanta Sadhukhan wrote:
> Hi,
>
> From http://doc.trolltech.com/4.4/threads.html, I found that
> /Note that QCoreApplication::exec
> <http://doc.trolltech.com/4.4/qcoreapplication.html#exec>() must
> always be called from the main thread (the thread that executes
> main()), not from a QThread
> <http://doc.trolltech.com/4.4/qthread.html>. In GUI applications, the
> main thread is also called the GUI thread because it's the only thread
> that is allowed to perform GUI-related operations.
>
> /but in the attached application, I tried creating a linux thread from
> main and tries to call exec from the spawned thread and exec works.
> I guess as per above line, exec() should only be calling from thread
> running main() and not from the spawned thread, am I right?
> My question is is any thread a main thread so long it's not spawned by
> QThread api?
>
I also saw that from QCoreApplication::exec() that
Qt Code:
1.
int QCoreApplication
<http://doc.trolltech.com/latest/QCoreApplication.html>::exec()
2.
{
3.
if (!QCoreApplicationPrivate::checkInstance("exec"))
4.
return -1;
5.
6.
QThreadData *threadData = self->d_func()->threadData;
7.
if (threadData != QThreadData::current()) {
8.
*qWarning("%s::exec: Must be called from the main
thread",</b> self->metaObject()->className());*
9.
return -1;
10.
}
11.
that it will throw an warning as shown above if not called from main
thread but I did not get any warning, so I guess any thread can call
exec() so long the thread also does QApplication(argc, argv) and it's
not spawned by QThread api?
Can you please confirm?
Thanks
Prasanta
> Regards
> Prasanta
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20081202/f42e42a1/attachment.html
More information about the Qt-interest-old
mailing list