[Qt-interest] question about threads in console application
franki
franki at franki.eu.org
Tue Mar 22 11:29:50 CET 2011
Hi,
I'm building console application with several threads. So far I was creating
every object inside main() function and then I moved some of them to their
threads, and some stayed in main thread.
I have also installed handler for qDebug, qCritical and so one, inside main()
function like this:
qInstallMsgHandler(myMessageOutput);
So now if I'm doing some heavy computing stuff inside object created in main()
function, every other thread waits for it, till it finishes, even though they
are in separate threads with signal/slot connection type
Qt::QueuedConnection.
So I have two questions
1. Should I do another class like "MyAppClass" and create myAppClass object
inside main() function, so the function main() would be much cleaner, and
then inside myAppClass object I would create other objects and their threads,
make signal/slot connection and so one.
2. Should I create myAppThread inside mian() function (or myAppClass object)
and move every other objects (that don't have their own thread yet)
to "myAppThread" so in that way I leave first thread entirely for
qtApplication. As I observed, when I do that, threads don't wait for each
other while they are using qDebug which is, as I assume, from qtApplication
thread. Also if I do explicitly sleep (which is wrong of course) in some
thread (not qtApplication thread) other threads don't wait for that thread.
So in simple words: is it worth of effort to:
1. maintain clean main() function
2. maintain mainthread only for qtApplication and rest of the objects inside
separate thread/threads
best regards
Marek
More information about the Qt-interest-old
mailing list