You Are Here:

Community: Wiki

This page was last modified on 3 September 2009, at 07:39.

CS001427 - Using threads in Qt

From Forum Nokia Wiki


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

Overview

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.


Preconditions


Header (mythread.h)

#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;
};


Source (mythread.cpp)

#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();
}


Starting thread

thread = new MyThread(this);
thread->start();


See also


Postconditions

A part of the code is executed in a separate thread.

Related Wiki Articles

No related wiki articles found

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2findeE78E2ephpE2fHowE5ftoE5fsendE5fandE5freceiveE5fmessagesE5finE5fE51tE5fforE5fSymbianX qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqfntypeZWikiContentQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZE71tQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZtypeQUqfntypeZWikiContentQ qfnZuserE5ftagQSxE71tX qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqfntypeZWikiContentQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ