Qt UI Animation jerks in a multiThreaded application!
-
Hello All,
I have a problem while animating switching of screen in MultiThreaded Qt Application.
I have a multiThreaded application the main UI Thread and the worker Thread. I have set the UI Thread with TimeCriticalPriority and the worker thread with the Normal Priority. So that my UI does not freeze at any point of time. But when i try to animate a screen for switching from one screen to other screen I see jerks on the UI.
The problem here is, when the UI Thread is animating to switch the screens, the platform switches from UI Thread to the Worker thread resulting in jerks. How can i solve this issue ?
I suppose the following solutions might help me to resolve these issues. But how do i implement the solution ?
- Making the worker thread wait untill the animation in UI thread is finished.
- how should i make the worker thread wait ?
- Making the UI thread busy untill the animation gets over ?
- how can i make the worker thread busy ? (possible work around
solution might be calling some other functions in UI Thread so it does not switch to worker thread).
Is there any other way to switch the screens from left to right or vise versa without usingQPropertyAnimation in QT?
Any suggestion/help on this is highly appriciated.
Can anyone please let me know the possible solutions for this ?
Thanks in advance.
Best Regards
Varun Jajee -
I am waiting the reply also
-
You could try setting your worker thread to QThread::IdlePriority while the animation runs. No idea if this will work for your scenario; I never tried this.
-
Thank you Andre, for the suggestion.
As you suggested, I tried setting the worker thread to the IdlePriorit, but this did not help I can still find the jerks while animating.
In my case the worker thread is busy listening the events from other applications. What i observed is if the worker thread does not receive any events from the other application during the animation process than the animation of screens happens very smoothly. And if the worker thread receives any event during the animation process than I see jerks in the animation.
I was wondering, Is there any way to force the worker thread sleep during the animation process ?
-
I think that symbian is not supporting multitasking well.
I used a work around but i don't know if this is gonna work with you.
i tried to sleep the worker thread 5 seconds after every process. -
I'm working on windows CE 6.0.
Few things are not very clear for me.
I tried calling workerThred->wait(5000) from the main UI thread but this is blocking my main UI thread for 5000 mili seconds and not the worker thread, I suppose this is because worker thread was created on main UI Thread. And i am am not able to use sleep since Sleep() is a prtotected member funtion of a QThread.
-
note that wait blocks the thread that is called in until the associated thread is finished execution or the time is elapsed.
try to inherent from QThread and call sleep from inside the thread.
-
I face the simillar problem when i call sleep() from worker thread.
@
main()
{QAPP app();
...
..
WorkerThread *pThread =new WorkerThread;Display MainWindow(WorkerThread)
...
app.exe();
}MainWindow::UIEvent()
{
WorkerThread->sleep(2); // When i call this The UI thread sleeps for 2 seconds.
}
@Please do let me know, In case if you feel i might be doing something wrong.
Thank you
Varun[EDIT: code formatting, please wrap in @-tags, Volker]
-
I could resolve this issue using Scrolling of widgets to see the smooth transformation of screens. but i some how feel this is not the right way because i am scrolling the screens 10 pixel every time in a event loop untill the transformation of screen is done.
Any other suggestions are welcomed.
-
@varunjajee: you said "I tried calling workerThred->wait(5000) from the main UI thread but this is blocking my main UI thread for 5000 mili seconds and not the worker thread" -- and yes, this is because you called that function from the main thread. Have you read http://developer.qt.nokia.com/wiki/Threads_Events_QObjects as it's a very useful resource.
You state that while the UI thread is performing the animation, the OS is performing a context switch and the worker thread is running, causing the animation to jerk. Note that there are other possibilities (eg, the main thread doing something which requires acquiring locks, resulting in codepaths which take a substantial amount of time, being run -- resulting in skipped frames, etc) which could cause jerky animation, but from your description it does seem like a context switch is occurring so that the worker thread can handle the events posted to it.
I don't know whether this would work, but to solve that problem you could try sending a high-priority event from the main thread to the worker thread, telling it to wait on a mutex / semaphore; then once the main ui has finished the animation, release the mutex or decrement the semaphore, which allows the worker thread to continue processing events.
Good luck!