Results 1 to 5 of 5

Thread: SetText/SetValue for QLabel/QSlider severely slows down application

  1. #1
    Join Date
    Nov 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default SetText/SetValue for QLabel/QSlider severely slows down application

    I've a Video application. It consists of some different widgets.

    I use on QGraphicsScene with OpenGL to render a video clip. This is done by drawing a square using polygon and then applying a texture, the video frame, on that polygon. Doing that will let the hardware scale everything. But I have a real performance problem.

    The QGraphicsScene has a timer that will get the next frame and then call update. It also will emit a signal telling the new frame number. There are one other widget that will listen to this signal and update a QLabel with how many seconds have been played. A QSlider is also updated to visualize how far in the movie we are. Doing these two updates will slow down the application extreme.

    When playing a clip with 60 fps and NOT updating the QLabel and QSlider I can see that the timer will generate a signal each 16 mS (exactly what the timer is set on). But when updating the QLabel/QSlider it will take between 30-40 mS between the timer timeout even though it is set to 16 mS.

    I think I've made som thread problem, but can not really figure it out.

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: SetText/SetValue for QLabel/QSlider severely slows down application

    Just a guess (its hard to do more without seeing some code), but maybe the QSlider's "valueChanged()" signal is connected to a slot where you grab frame, to let user navigate the video with the slider. So it could happen that each frame is grabbed twice - once when you grab it with timer, then you update the slider - the slider generates "valueChanged" signal, which launches a slot that grabs the same frame again.
    I'm just guessing, but the processing time is ~2x longer, so maybe thats the case.
    We can help more if you show us some code.

  3. #3
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: SetText/SetValue for QLabel/QSlider severely slows down application

    Updating the slider 60 times per second sounds bit extreme (if that's what you're doing).

    Test how long it takes to update the QLabel/QSlider on its own without any extra strings attached, in my case it's well below a ms (~0.02 in fact).

    Try to add another timer that fires every 1s and updates the label/slider.

  4. #4
    Join Date
    Nov 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: SetText/SetValue for QLabel/QSlider severely slows down application

    Quote Originally Posted by stampede View Post
    Just a guess (its hard to do more without seeing some code), but maybe the QSlider's "valueChanged()" signal is connected to a slot where you grab frame, to let user navigate the video with the slider. So it could happen that each frame is grabbed twice - once when you grab it with timer, then you update the slider - the slider generates "valueChanged" signal, which launches a slot that grabs the same frame again.
    I'm just guessing, but the processing time is ~2x longer, so maybe thats the case.
    We can help more if you show us some code.
    I'm sorry for the late replay, I've been in parts of Sweden where there are no connection on my mobile internet :-(

    No! I have fixed that one before I find this problem :-)

    I've measured how long it take just to update the QSlider and QLabel. If I use a QTimer it says 0 mS. So I'm pretty sure that it is not the time that it takes to change the value that's the problem. I'm more thinking that the has to be some thread scheduling problem or simular.

    Just for the fun of it I put in a small loop instead of updating the QLabel/QSlider. This loop is just doing som random calculations on random numbers (no way for the compiler to optimize). I made that loop just to burn CPU power for about 5-10 mS. Even when doing that there is no problem. The problem occurs when I start updating controls in the Qt UI.

    The rational by updating the slider 60 times per second is that the slider is pretty wide and I want to have a smooth movement. It would probably be ok to have it update the slider 5-15 times per second, but as I see it that is just to but a bandaid on the problem and not fixing the source of the problem.

  5. #5
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: SetText/SetValue for QLabel/QSlider severely slows down application

    You need to show us some code if possible, it'll be much easier this way.

Similar Threads

  1. QLabel->setText() cause memory incerase
    By gozdemir in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 11th July 2011, 11:14
  2. QLabel->setText() sometimes not working
    By cass in forum Newbie
    Replies: 8
    Last Post: 16th May 2010, 13:12
  3. QLabel setText Problem
    By pmabie in forum Qt Programming
    Replies: 10
    Last Post: 1st November 2007, 23:32
  4. Problem with QLabel and setText
    By jambrek in forum Qt Programming
    Replies: 7
    Last Post: 31st October 2007, 16:02
  5. QLabel::setText() how to
    By freak in forum Qt Programming
    Replies: 1
    Last Post: 30th October 2006, 17:19

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.