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!!
Bookmarks