Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.
Using threads in Qt
S60 5th Edition
This code snippet demonstrates how to implement platform-independent threads in Qt by using the QThread class. Instead of starting in main(), the execution of QThreads begins in run(). By default, run() starts the event loop by calling exec().
Tip: There is a useful blog on this topic in Qt blogs here: http://labs.qt.nokia.com/2010/06/17/youre-doing-it-wrong/ which indicates (among other things) that subclassing QThread may not be approach. This is well worth reading to understand the implications of various approaches
- Install latest Qt using Qt SDK
MyThread::MyThread(QObject* parent) : QThread(parent)
// TODO: there you can run some part of your code in
// different thread that rest of the application
// You can create needed classes here or also in MyThread construction.
// Thread enters the event loop and waits until exit() is called
void MyThread::setData(int someData)
data = someData;
thread = new MyThread(this);
- Using your own class as a signal and slot parameter in QThread
- For more information about QThread, see QThread Class Reference.
A part of the code is executed in a separate thread.