[Qt-interest] Basic Qthread question - part 4

Thiago Macieira thiago at kde.org
Wed May 5 10:29:15 CEST 2010


Em Quarta-feira 05 Maio 2010, às 10:07:18, Phil escreveu:
> I must nearly have this correct, surely.
>  
> Timer::Timer(QObject *parent) : QThread(parent)

There are only two mentions of QThread in your code. One is above, the other 
is below, starting the thread.

Besides that, there's nothing threading-related in your code.

The QTimer class is created in the main thread (the one running the 
constructor here). This current class is also created in the main thread, so 
the slot connection below is a DirectConnection. The timer runs in the main 
thread and the getData slot is called in the main thread.

> {
>     timer_.setInterval(1000);
> 
>     connect(&timer_, SIGNAL(timeout()), this, SLOT(getData()));
> 
>     QThread::start();
> }
> 
> Timer::~Timer()
> {
> }
> 
> void Timer::run()
> {
>     //should I have some useful code here? 
>     exec();
> }
> 
> void Timer::getData()
> {
>     // time-intensive operation here
>     ........
> 
>     //display the data on the GUI       
>     emit dataReady(list);
> }

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Senior Product Manager - Nokia, Qt Development Frameworks
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100505/335e33f5/attachment.bin 


More information about the Qt-interest-old mailing list