Results 1 to 6 of 6

Thread: qthread / qtimer

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2010
    Posts
    17
    Qt products
    Qt4
    Platforms
    Windows

    Default qthread / qtimer

    edit: sorry, figured this one out so I'm changing the topic. I'd like to be able to stop and start this qtimer from within the timeoutHandler slot, but doing so gives errors about killing a timer from a different thread. The code below is just an example and in the real deal it would check a shared variable (modified by the parent) for a pause request, then use QMutex and QWaitCondition to control the pause. Does this sound like something that should even be possible in the first place? I've gotten around this by having the parent control the QTimer externally, but I'd rather all the load be in the child thread.

    QObject::killTimer: timers cannot be stopped from another thread"
    QOBject::startTimer: timers cannot be started from another thread"

    Qt Code:
    1. void ThreadWatcher2::run() {
    2. updateTimer = new QTimer();
    3.  
    4. QSignalMapper signalMapper;
    5.  
    6. for (int i=0; i<6; i++) {
    7. connect(thread[i], SIGNAL(finished()), &signalMapper, SLOT(map()));
    8. signalMapper.setMapping(thread[i], i); }
    9.  
    10. connect(&signalMapper, SIGNAL(mapped(int)), this, SLOT(finishedHandler(int)));
    11.  
    12. connect(updateTimer, SIGNAL(timeout()), this, SLOT(timeoutHandler()));
    13.  
    14. updateTimer->start(10);
    15.  
    16. QThread::exec();
    17. }
    18. void ThreadWatcher2::timeoutHandler() {
    19. for (int i=0; i<6; i++)
    20. window[i]->update();
    21.  
    22. updateTimer->stop();
    23. updateTimer->start(10);
    24.  
    25. if (threadsLeft==0)
    26. QThread::exit(0);
    27. }
    28. void ThreadWatcher2::finishedHandler(int t) {
    29. threadsLeft--;
    30. QTextStream cout(stdout, QIODevice::WriteOnly);
    31. cout << "t: " << t << endl;
    32. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Galen; 16th April 2010 at 05:24.

Similar Threads

  1. get finished signal from a thread
    By ProTonS in forum Qt Programming
    Replies: 4
    Last Post: 21st August 2009, 14:17
  2. QProcess::finished()
    By T1c4L in forum Qt Programming
    Replies: 11
    Last Post: 9th July 2008, 20:06
  3. lost signals ?
    By deepinlife in forum Qt Programming
    Replies: 3
    Last Post: 17th June 2008, 10:11
  4. QThread and signals (linux/UNIX signals not Qt Signals)
    By Micawber in forum Qt Programming
    Replies: 1
    Last Post: 28th November 2007, 22:18
  5. QUrlOperator::copy sends two finished signals
    By hvengel in forum Qt Programming
    Replies: 5
    Last Post: 29th May 2007, 19:42

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.