Results 1 to 4 of 4

Thread: [SOLVED]QTimer::remainingTime() returning negative numbers diff. from -1 ?!

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2013
    Posts
    9
    Qt products
    Qt5
    Platforms
    Windows

    Question [SOLVED]QTimer::remainingTime() returning negative numbers diff. from -1 ?!

    Hi everyone,
    I'm using a QTimer in a multithread Qt5 application. Here is my structure:

    Main application (MainWindow.cpp) creates a thread "ComputeScores" that creates N threads "AlgorithmTest" in its run() method. In each of these "AlgorithmTest" threads run() methods, I'm creating a timer to give to a particular algorithm some time budget (once the time is elapsed, the algorithm has to give the best answer it found during this interval).

    So what I do in some of my algorithm steps to check the budget isn't exhausted is testing that the reamining time of my timer is not 0. But it turned out that QTimer has a strange behaviour...
    When I start my algorithm in "AlgorithmTest" run(), the first thing I do is "myTimer.start(myBudget);". Then as second instruction, for testing purposes, I print myTimer.remainingTime() rightaway with "qDebug() << myTimer.remainingTime()".
    The first time it prints (so for the first call to start()), it prints... 0. Then the second time, it prints a random negative number (always a negative one) like -613230304. So of course the rest of my program just makes everything wrong (like infinite loop as the time never reaches 0, even if sometimes it does, despite of the negative remainingTime ?!).

    I just don't know what to do here, I googled that and nobody has never seen negative remaining times I think... :/

    Thank you in advance!!
    Last edited by Data42; 27th August 2013 at 23:10.

Similar Threads

  1. Replies: 7
    Last Post: 15th February 2012, 13:51
  2. Negative numbers on QLineEdit
    By Cucus in forum Qt Tools
    Replies: 1
    Last Post: 22nd April 2011, 13:51
  3. How to use QLCDnumber to display negative numbers?
    By grissiom in forum Qt Programming
    Replies: 1
    Last Post: 19th March 2010, 06:23
  4. Diff between QBrush and QPen
    By wagmare in forum Qt Programming
    Replies: 5
    Last Post: 16th February 2009, 14:47
  5. Diff between QImage, QPixmap, QPicture
    By nupul in forum Newbie
    Replies: 6
    Last Post: 30th April 2008, 02:02

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.