Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Qt UI Animation jerks in a multiThreaded application!
Forum Updated to NodeBB v4.3 + New Features

Qt UI Animation jerks in a multiThreaded application!

Scheduled Pinned Locked Moved Mobile and Embedded
10 Posts 4 Posters 6.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    varunjajee
    wrote on 25 Oct 2011, 15:12 last edited by
    #1

    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 ?

    1. Making the worker thread wait untill the animation in UI thread is finished.
    • how should i make the worker thread wait ?
    1. 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

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mismail
      wrote on 26 Oct 2011, 09:52 last edited by
      #2

      I am waiting the reply also

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on 26 Oct 2011, 10:29 last edited by
        #3

        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.

        1 Reply Last reply
        0
        • V Offline
          V Offline
          varunjajee
          wrote on 26 Oct 2011, 10:52 last edited by
          #4

          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 ?

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mismail
            wrote on 26 Oct 2011, 11:02 last edited by
            #5

            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.

            1 Reply Last reply
            0
            • V Offline
              V Offline
              varunjajee
              wrote on 26 Oct 2011, 11:10 last edited by
              #6

              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.

              1 Reply Last reply
              0
              • M Offline
                M Offline
                mismail
                wrote on 26 Oct 2011, 12:05 last edited by
                #7

                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.

                1 Reply Last reply
                0
                • V Offline
                  V Offline
                  varunjajee
                  wrote on 26 Oct 2011, 12:43 last edited by
                  #8

                  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]

                  1 Reply Last reply
                  0
                  • V Offline
                    V Offline
                    varunjajee
                    wrote on 27 Oct 2011, 08:50 last edited by
                    #9

                    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.

                    1 Reply Last reply
                    0
                    • C Offline
                      C Offline
                      chriadam
                      wrote on 27 Oct 2011, 23:57 last edited by
                      #10

                      @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!

                      1 Reply Last reply
                      0

                      1/10

                      25 Oct 2011, 15:12

                      • Login

                      • Login or register to search.
                      1 out of 10
                      • First post
                        1/10
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved