Solved QTimer with zero timeout not work
-
QTimer with zero timeout works different from what is described in doc. If the QTimer is in the main thread, the GUI interface will freeze. If I new a QTimer in an object affiliated to another thread and set the timeout to zero, It would work fine.
-
@cengzm
Hi and welcome to devnetYou may want tocheck with Qt bug tracker JIRA if there is already a bug reported. If it is not reproted you can enter it there. This forum is not tracked for bug reports and their solution. Therefore, bugs reported here may be noticed by some people, but they almost certainly get lost.
-
My computer is armed with 8 cpu cores and if I use the QTimer in a thread other than the GUI thread and set the timeout to be zero, the CPU consumption of my program would be about 13%, and one of the cpu cores is never idle. Why the time slice schedule policy not work here?
-
Hi
If you do something likevoid MainWindow::ProcessText() { qDebug() << "test"; // GIGA FOR LOOP } void MainWindow::on_pushButton_released() { QTimer* timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(ProcessText())); timer->start(); }
and ProcessText() takes a long time,it will block GUI thread.
"ProcessText()" must do the task step wise as not to block. -
@mrjj
I have tried to set the slot to be an empty function(do nothing at all) and still get freezed. And my desktop will freeze too, I must use Ctl+Shift+Esc to call out the task manager to end the process to continue. -
Ok that sounds odd.
If you create a new default GUI project and use the code above,
does it still do i t?
Here is prints tons of "test" but nothing lags.
If you can reproduce it in a minimal sample, you might found bug.
ps. Windows 7, 64bit, mingw compiler. qt 5.5 -
@mrjj
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
QTimer * timer = new QTimer(this);
QLineEdit * le = new QLineEdit(this);
connect(timer,SIGNAL(timeout()),this,SLOT(test()));
timer->start();
}MainWindow::~MainWindow()
{}
void MainWindow::test()
{
static int i=0;
if(0 == i%1000)
qDebug()<<"test";
i++;
}
test result is:
1, I can see the "test" output at the console
2, I can input in the lineedit, minimum and maximum the main window
3, once I try to move the main window, the system gets freezed.
ps. windows 7, 64bit, msvc2012 compiler, qt 5.0.2 -
@koahnig
Thanks and I have searched the bug report list and nothing related is found. I've reported the issue as QTBUG-7618. It seems I should try another release for luck... -
@cengzm said:
qt 5.0.2
If possible upgrade to newer Qt and see of problem exists.
I see nothing wrong and your code works fine here even when moving window.
Could be a bug, or something local.
-
@mrjj
Thanks for you response very much. I would try a newer release. -
@mrjj
I setup Qt5.5.1 and test the same code. Everyting works fine~ -
@cengzm
So odd bug in 5.0.2 ? -
@cengzm said:
I setup Qt5.5.1 and test the same code. Everyting works fine~
Good news!
Please update your bug report with this info. Qt 5.0.2 is very old.