Screen switching with Scrolling effect
-
wrote on 26 Oct 2011, 14:08 last edited by
well imo animation framework is the best way. but you could try using QTimeline and changing the widget position.
or a scroll area where the scrolling is animated. -
wrote on 26 Oct 2011, 17:27 last edited by
Thanks for your inputs, I could implement changing of screen using the widget scrolling without using Animation framework. this solved a problem which i was facing in my application( chocking of UI thread).
-
wrote on 26 Oct 2011, 17:59 last edited by
well normally animation framework doesn't freeze the gui thread. can you post your code?
-
wrote on 27 Oct 2011, 08:25 last edited by
I will not be able to post the code. But i can explain you the scenario.
Basically, I have a multiThreaded application UI Thread with higher priority and Worker thread with NormalPriority. The Worker thread continuously listens to the events from other applications throught out the life time.
When i start an animation of switching the screen by setting the animation duration of setDuration(1500); the animation happens smoothly in the UI thread. only if the worker thread does not receive any events. And I can see the chocking effect in the animation if the worker thread receives any event form other applications during the animation.
The reason is, While the UI thread is animating it switches to the worker thread if the worker thread receives an event resulting in chocking effect in the UI.
If i use the scrolling of widgets instead of animation. than in this case the UI thread does not switch to the workder thread untill it process all the events in its event queue. resulting in smooth scrolling. To achive this I'm scrolling 10 pixel ever time in a event loop. so that i can see the smooth scrolling.
Please do suggest me if you have any other scenarios(or other way) which i can try ? So that i can see smooth animation with out chocking effects.
-
wrote on 27 Oct 2011, 08:37 last edited by
so you run the code on a single cpu application? or does the worker thread in case of an event needs information of the gui thread? Perhaps a bit dirty but can't you sleep the worker thread during the animation?
-
wrote on 27 Oct 2011, 08:43 last edited by
Yes, It is a single application but the worker thread interacts with other application to get the information about the device, etc etc. I tried to sleep the worker thread but it did not work.
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 faced the similar issues when i called the Sleep(). -
wrote on 27 Oct 2011, 08:47 last edited by
have you tried to send a signal to the thread, and in the threads slots a call to QThread::currentThread()->wait() ?
-
wrote on 27 Oct 2011, 08:54 last edited by
Yes, I had tried this out yesterday. but some how the animation was not that smooth.
I was getting an error/Message :- QThread tried to wait on itself. I could not understand what was this message. Was it an error ? And i could not really understand whether the thread was waiting or not.
-
wrote on 27 Oct 2011, 08:58 last edited by
i think you'll have to sleep the thread instead of waiting. you can read more about that in the Doc
-
wrote on 27 Oct 2011, 09:14 last edited by
thanks for your suggestions again.
I had spent good amount of time on this. But at last got puzzled. Sleep() is a protected memebr function and can not be called directly.
To call sleep() I will have to derive a class say -MyThread from QThread.
but when i post the event from one thread to other thread i will have to post the event on QObject whcih shoule be running in Worker QThread. to achive this i will have to call MoveToThread().And now when i send the postevent() from UI thread to worker thread. The QObject event loop in the worker thread receives the event. And in QObject to access its thread i will have to use thread() which returns QThread not MyThread.Since Sleep() being a protected member wont be able to access it. do i need to typecast from QThread to MyThread and access sleep() ? I havn't tried this ? I wonder will this work or not.
-
wrote on 27 Oct 2011, 09:35 last edited by
so do you actually derive from QThread in your app or not?
and if you send a signal to you thread f.e. sleep(int) to the thread slot onSleep(int) you can just call "your" member function sleep(int) without any cast. and you don't have to post events to the threads, signals are fine
-
wrote on 27 Oct 2011, 15:33 last edited by
I can call the sleep() from the run method. But i was wondering this might not be a clean design. I will look into this at later point of time. if you come across any other information regarding simillar issues than please keep me posted
11/13