[Qt-interest] timers cannot be started from another thread
Bartosh Wroblevksy
bartosh at live.com
Mon Jul 20 18:49:25 CEST 2009
I had this problem and I came to the conclusion that it is more appropriate and more precise to use QWaitCondition http://doc.trolltech.com/4.3/qwaitcondition.html when doing thread programming and time is needed to delay stuff. What do you think?
Also if the QTimer is not associated with the thread GratingVariationShowMovie, your direct connection may fail big time. Try a powerTimer.movetoThread( this ). Also I don't see an exec() which would run the eventLoop of your thread GratingVariationShowMovie.
Is there no way you could use QWaitCondition here?
> Date: Mon, 20 Jul 2009 18:18:55 +0200
> From: matthias.pospiech at gmx.de
> To: qt-interest at trolltech.com
> Subject: [Qt-interest] timers cannot be started from another thread
>
> In short: Is there any possibilty of having a timer within a thread?
>
>
> I want to have a Timer in a QThread.
>
> The thread is working with some devices such as translationstages.
> Parallel I have a second setup which I want to change at defined time
> intervalls.
>
> Therefore I set up the following (simplified):
>
> class GratingVariationShowMovie: public QThread
> {
> Q_OBJECT
> public:
> GratingVariationShowMovie() { }
>
> virtual ~GratingVariationShowMovie(){}
>
> private:
> QTimer powerTimer;
>
> private slots:
> void OnPowerTimerTimeout()
> {
> double destination =
> powerTimeline[powerTimelineIndex].powerPosition;
> RotationStage->PowerOn();
> RotationStage->move(destination / RotationStage->CountsToDegree());
>
>
> powerTimer.setInterval(powerTimeline[powerTimelineIndex].timeUntilChange);
> powerTimer.start();
> powerTimelineIndex++;
> }
>
> public:
>
> void run()
> {
> connect(&powerTimer, SIGNAL(timeout()), this,
> SLOT(OnPowerTimerTimeout()), Qt::DirectConnection);
> runThread();
> }
>
> void runThread()
> {
>
> OnPowerTimerTimeout();
> ...(main activity)
> }
>
> };
>
> This however gives me the error "timers cannot be started from another
> thread"
>
> If I change the timer to a pointer and construct it in the run() method,
> then I get the error:
>
> QObject: Cannot create children for a parent that is in a different thread.
> (Parent is GratingVariationShowMovie(0x1efe100), parent's thread is
> QThread(0xe1
> 7080), current thread is GratingVariationShowMovie(0x1efe100)
> QObject::killTimer: timers cannot be stopped from another thread
>
> confused....
>
> Matthias
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
_________________________________________________________________
More storage. Better anti-spam and antivirus protection. Hotmail makes it simple.
http://go.microsoft.com/?linkid=9671357
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090720/0ebba465/attachment.html
More information about the Qt-interest-old
mailing list