Hi All,
I want to Implement Sleep() or wait() in Qt.
I have used QTest::sleep(250); but it not work properly in my application.
Is there any another option that I can use?
Hi All,
I want to Implement Sleep() or wait() in Qt.
I have used QTest::sleep(250); but it not work properly in my application.
Is there any another option that I can use?
How about ::Sleep(ms) ?
But what do you mean by "not work properly" ?
Actually I am using Thread and I want to Pause the main application for few sec to receive the data but when I Implement QTest class I got error, It might be possible that I am not implementing properly. Please help me how to use the Sleep() in Qt.
I don't know what you design is, but this sounds like trouble.Actually I am using Thread and I want to Pause the main application for few sec to receive the data
You should not make the main GUI thread wait, it also makes no sense, if you are using threads, that is what thread are for - to allow parallel execution.
If you want the application thread to wait, you actually don't need another thread, just do your task in the main thread, it will then wait for your task to end.
But note, that as long as the GUI thread waits for your task to finish, the application will be non responsive, since no events will be handled by the application.
Never the less, QThread has a public wait and protected sleep functions.
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
Is there a reason why the thread can not send signal to main application thread to state when the data is ready instead of waiting for it? As high_flyer says, waiting in my thread is very bad. On Windows, this can cause the OS to place the text "Not Responding" on your window, as you will not be replying to messages from the OS.
Read more about QWaitCondition. There is a wait() function that is what you need.
Bookmarks