Results 1 to 5 of 5

Thread: refreshing labels

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 541 Times in 521 Posts

    Default Re: refreshing labels

    You set the numbers too fast. The label doesn't get the chance to update.
    You should use a QTimer with an interval of 100-200ms. Connect its timeout signal to a slot in which you update the label with a new value. Then you will be able to see something.

  2. The following user says thank you to marcel for this useful post:

    ht1 (29th December 2007)

  3. #2
    Join Date
    Nov 2007
    Posts
    47
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    34

    Default Re: refreshing labels

    Thanks Marcel, but I think something else than speed is the problem.
    The code that I designated as (//main code here) is very long and takes a long time to compile. The labels have about a minute to refresh. Maybe the labels don't refresh because the processor is 100% busy with doing the math?

  4. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    28
    Thanked 976 Times in 912 Posts

    Default Re: refreshing labels

    Quote Originally Posted by ht1 View Post
    Maybe the labels don't refresh because the processor is 100% busy with doing the math?
    Yes, you block the Qt's event loop and Qt can't redraw anything or even process user's input. You can avoid this by invoking QCoreApplication::processEvents() from time to time or using QTimer to drive your loop. A third option is to move those computations to a thread.

  5. The following user says thank you to jacek for this useful post:

    ht1 (29th December 2007)

  6. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts

    Default Re: refreshing labels

    In other words, events don't get processed during a busy loop. When you change the contents of a label, a few events get scheduled (to update the label). But no event reaches its receiver until you return the control to the event loop. One simple but a bit ugly solution is to force the application to process its events:
    Qt Code:
    1. for (int kk=1; kk<100; kk++)
    2. {
    3. //main code is here
    4. Label->setNum(kk);
    5. QApplication::processEvents(); // <--
    6. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  7. The following user says thank you to jpn for this useful post:

    ht1 (29th December 2007)

Similar Threads

  1. Tick Labels for Slider
    By jcraig in forum Qt Tools
    Replies: 2
    Last Post: 9th August 2007, 18:21
  2. QSlider with a custom set of labels for the tick marks?
    By whitefurrows in forum Qt Programming
    Replies: 3
    Last Post: 5th August 2007, 17:05
  3. setting QTreeWidget vertical labels
    By hyling in forum Qt Programming
    Replies: 2
    Last Post: 10th January 2007, 19:53
  4. Refreshing problem
    By jaime in forum Qt Programming
    Replies: 3
    Last Post: 24th August 2006, 23:09
  5. Replies: 1
    Last Post: 23rd August 2006, 19:02

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
  •  
Qt is a trademark of The Qt Company.