Delay produce in qt C++ for qt 4.8.7
-
I want to produce delay in my code for 500ms. I have tried following commands.
1). QThread::msleep(500);
2). delay(500);
3). sleep(500);command (1). produce delay but when I deploy the project to my SDR board it pops error that "QThread cannot yous in this scope" because my board running qt4.8.7 not the latest. So I used 2). and 3). but they are not working.
Please guide me how I can produce a delay for qt4.8.7 version. -
I want to produce delay in my code for 500ms. I have tried following commands.
1). QThread::msleep(500);
2). delay(500);
3). sleep(500);command (1). produce delay but when I deploy the project to my SDR board it pops error that "QThread cannot yous in this scope" because my board running qt4.8.7 not the latest. So I used 2). and 3). but they are not working.
Please guide me how I can produce a delay for qt4.8.7 version.@Mijaz It is already supported in Qt4: https://doc.qt.io/archives/qt-4.8/qthread.html#msleep
When and where do you get that error? -
@Mijaz It is already supported in Qt4: https://doc.qt.io/archives/qt-4.8/qthread.html#msleep
When and where do you get that error?@jsulm said in Dealy produce in qt C++ for qt 4.8.7:
It is already supported in Qt4: https://doc.qt.io/archives/qt-4.8/qthread.html#msleep
QThread::msleep()
is public in Qt 5 but protected in Qt 4. So, Qt 4,QThread::msleep()
must be called by a QThread subclass. -
@jsulm said in Dealy produce in qt C++ for qt 4.8.7:
It is already supported in Qt4: https://doc.qt.io/archives/qt-4.8/qthread.html#msleep
QThread::msleep()
is public in Qt 5 but protected in Qt 4. So, Qt 4,QThread::msleep()
must be called by a QThread subclass. -
I want to produce delay in my code for 500ms. I have tried following commands.
1). QThread::msleep(500);
2). delay(500);
3). sleep(500);command (1). produce delay but when I deploy the project to my SDR board it pops error that "QThread cannot yous in this scope" because my board running qt4.8.7 not the latest. So I used 2). and 3). but they are not working.
Please guide me how I can produce a delay for qt4.8.7 version. -
@Mijaz all the calls you mentioned are blocking. The better way is to use a QTimer and connect a slot to the timeout() signal.
Regards
-
@aha_1980
I tried to use QTimer but I don't understand, how it will use for my purpose.
Will you please help me to write a simple widget program in which when I click a pushButton1 the LineEdit start blink and when click pushButton2 LineEdit stops blink.@Mijaz You have it here: https://forum.qt.io/topic/65799/how-to-display-label-for-30-seconds-and-then-hide-it/30
There is really nothing special to it:QTimer *timer = new QTimer(this); connect(timer, &QTimer::timeout, this, &MainWindow::toggleLineEdit); timer->start(1000); void MainWindow::toggleLineEdit() { ui->lineEdit->setChecked(!ui->lineEdit->checked()); ... }
Your both buttons then simply start the timer or stop it.
-
Hi @Mijaz
You can also use QEventLoop check below methods from documentation.
- exec() : Enters the main event loop and waits until
exit()
is called. Returns the value that was passed toexit()
. - exit() : Tells the event loop to exit with a return code.
Hope this may help you.
All the best. - exec() : Enters the main event loop and waits until