| ID | CS001427 | Creation date | June 16, 2009 |
| Platform | S60 3rd Edition, FP1, FP2 S60 5th Edition | Tested on devices | Nokia 5800 XpressMusic |
| Category | Qt for Symbian | Subcategory | Base/System |
| Keywords (APIs, classes, methods, functions): QThread |
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().
Note: In order to use this code, you need to have Qt for S60 installed on your platform.
#include <QObject>
#include <QThread>
class MyThread : public QThread
{
Q_OBJECT
public:
MyThread(QObject* parent = 0);
virtual ~MyThread();
public: // From QThread
void run();
signals:
void dataChanged();
public slots:
void setData(int someData);
private:
int data;
};
#include "mythread.h"
MyThread::MyThread(QObject* parent) : QThread(parent)
{
}
MyThread::~MyThread()
{
}
void MyThread::run()
{
// 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
exec();
}
void MyThread::setData(int someData)
{
data = someData;
emit dataChanged();
}
thread = new MyThread(this);
thread->start();
A part of the code is executed in a separate thread.
No related wiki articles found