[Qt-interest] how to set up loop with timer
Eirik Ulvik
eiriku at simsurgery.com
Thu May 6 09:59:02 CEST 2010
Den 06.05.2010 09:55, skrev Hannu Shemeikka:
> Hi,
>
> You could use something like this:
>
> timer = new QTimer(this);
> connect(this->timer, SIGNAL(timeout()), rThread, SLOT(yourSlotName()));
> this->timer->start(2000); // 1 = 1 ms
>
> This fires slot 'yourSlotName' in rThread (another QThread class) every
> 2 seconds.
>
> Or in the constructor of your thread:
>
> timer = new QTimer(this);
> connect(this->timer, SIGNAL(timeout()), this, SLOT(yourSlotName()));
> this->timer->start(2000); // 1 = 1 ms
>
If you want to do this in its own thread remember to start the threads
own event loop in the run function ie.:
class MyThread : public QThread
run()
{
exec();
}
There is also some problems with this approach. To get it working I used
the recipe found here:
http://lists.trolltech.com/qt-interest/2007-09/thread00073-0.html.
Good luck
Eirik
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 551 bytes
Desc: OpenPGP digital signature
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100506/21c3eaa1/attachment.bin
More information about the Qt-interest-old
mailing list