Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Delay for QLabel test update

Delay for QLabel test update

Scheduled Pinned Locked Moved General and Desktop
7 Posts 5 Posters 4.6k Views
  • 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.
  • F Offline
    F Offline
    fnoyanisi
    wrote on last edited by
    #1

    Hi

    I have a desktop application that processes a TXT file which is located by the user. To inform the user about the process, I use some QLabels and update text of label about the process being held.

    @ QLabel informer;
    informer.setText("Running...");
    while (not_end_of_file) {
    process_file();
    } @

    But the QLabel's text is updated after the while() loop finishes.

    What should I do to update the text before entering the loop.

    Thanks

    1 Reply Last reply
    0
    • C Offline
      C Offline
      cincirin
      wrote on last edited by
      #2

      @ QLabel informer;
      informer.setText("Running...");
      QCoreApplication::processEvents();
      while (not_end_of_file) {
      process_file();
      } @

      1 Reply Last reply
      0
      • R Offline
        R Offline
        rokemoon
        wrote on last edited by
        #3

        When you call "setText":http://doc.qt.nokia.com/latest/qlabel.html#text-prop changes will redraw in paintEvent so it will be calling in event loop, until while() not ends there is no repainting to label.
        As @cincirin wrote you need "processEvents":http://doc.qt.nokia.com/latest/qcoreapplication.html#processEvents before you call while(...)
        [EDIT:] mistakes in explanation

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          It is a bit saver to change line 3 above into:
          @
          QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents | QEventLoop::ExcludeSocketNotifiers);
          @
          That way, you can be sure that user input will not be processed at that point, which is a Good Thing(TM) as your application is probably in an inconsistent state: you do not anticipate such interaction at that point. Otherwise, you might find that a button-click signal could be processed at that moment, for instance.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            [quote author="rokemoon" date="1321441421"]"setText":http://doc.qt.nokia.com/latest/qlabel.html#text-prop is a slot so it will be calling in event loop, until while not ends there is no changing to label.[/quote]
            That is wrong:
            Slots are not called through the eventloop if the object the slot is in has the affinity of the current thread. Furthermore, slots are just methods, and that is way setText is called here. That completely circumvents the signal-slot mechanism, even if this call would be across threads (in which case, it would be wrong, as you cannot call anything that changes the UI from outside the UI thread, but that is different topic).

            1 Reply Last reply
            0
            • R Offline
              R Offline
              rokemoon
              wrote on last edited by
              #6

              [quote author="Andre" date="1321441817"]
              [quote author="rokemoon" date="1321441421"]"setText":http://doc.qt.nokia.com/latest/qlabel.html#text-prop is a slot so it will be calling in event loop, until while not ends there is no changing to label.[/quote]
              That is wrong:
              Slots are not called through the eventloop if the object the slot is in has the affinity of the current thread. Furthermore, slots are just methods, and that is way setText is called here. That completely circumvents the signal-slot mechanism, even if this call would be across threads (in which case, it would be wrong, as you cannot call anything that changes the UI from outside the UI thread, but that is different topic).

              [/quote]
              Oh my God what I'm telling about o_O , really SORRY. of course not in event loop it's just a method.
              That's all, I need the rest and should go home :-(

              1 Reply Last reply
              0
              • G Offline
                G Offline
                goetz
                wrote on last edited by
                #7

                A [[doc:QProgressDialog]] seems to be a better solution for this than a QLabel. Have a look at "this older thread":/forums/viewthread/1436, especially at the "snippet here":/forums/viewreply/43702/.

                Edit: fixed documentation link from QProcessDialog to QProgressDialog; Andre

                http://www.catb.org/~esr/faqs/smart-questions.html

                1 Reply Last reply
                0

                • Login

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