[Qt-interest] question about threads in console application
Anton Chernov
mechernov at gmail.com
Tue Mar 22 13:41:11 CET 2011
A clean main function sounds great! And if all other functions are
clean too you are programming with qt!
The thing is that you get a reaction on a event from the other thread
only in the qApp->processEvents(); If you do some heavy stuff you can
call that method to see if there is some processing to do.
To make it clean take a look at QtConcurrent.
2011/3/22 franki <franki at franki.eu.org>:
> 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
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
>
More information about the Qt-interest-old
mailing list