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. Setting timeout for QLabel-Text without Signals&Sots
QtWS25 Last Chance

Setting timeout for QLabel-Text without Signals&Sots

Scheduled Pinned Locked Moved Solved General and Desktop
sleeptimeout
3 Posts 2 Posters 855 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.
  • T Offline
    T Offline
    TUStudi
    wrote on last edited by
    #1

    Hi,

    I am working on a GUI-Application and I have different Buttons. Under every Button I have a QLabel, which should show a Message for a certain time, e.g. 3 seconds.
    I do not want to use the status bar because it is not noticed at all or not immediately. I don't want to use a MessageBox either.
    So, I have 8 QLabels and I wrote a function for filling these Labels with a message:

    void MainWindow::setStatus(QString statusMessage, StatusWidget widget)
    {
    
        switch(statusWidget){
        case Data:
            ui->dataStatus->setText(statusMessage);
           /*set time out 3 seconds here */
          /* ui->dataStatus->text().clear()*/
            break;
    
        case File:
            ui->fileStatus->setText(statusMessage);
           /*set time out 3 seconds*/
          /*ui->dataStatus->text().clear()*/
            break;
    
        ....
         }
    }
    

    Usage:

    // When "ShowData" button is clicked..
    void MainWindow::on_showData_clicked(){
        setStatus("The data is being retrieved. Please wait..",Data)
    }
    

    So i hav read that it is not recommendet to use a Thread.sleep(), what would be a good alternative here without forcing the GUI to wait until the timeout is reached?

    JonBJ 1 Reply Last reply
    0
    • T TUStudi

      Hi,

      I am working on a GUI-Application and I have different Buttons. Under every Button I have a QLabel, which should show a Message for a certain time, e.g. 3 seconds.
      I do not want to use the status bar because it is not noticed at all or not immediately. I don't want to use a MessageBox either.
      So, I have 8 QLabels and I wrote a function for filling these Labels with a message:

      void MainWindow::setStatus(QString statusMessage, StatusWidget widget)
      {
      
          switch(statusWidget){
          case Data:
              ui->dataStatus->setText(statusMessage);
             /*set time out 3 seconds here */
            /* ui->dataStatus->text().clear()*/
              break;
      
          case File:
              ui->fileStatus->setText(statusMessage);
             /*set time out 3 seconds*/
            /*ui->dataStatus->text().clear()*/
              break;
      
          ....
           }
      }
      

      Usage:

      // When "ShowData" button is clicked..
      void MainWindow::on_showData_clicked(){
          setStatus("The data is being retrieved. Please wait..",Data)
      }
      

      So i hav read that it is not recommendet to use a Thread.sleep(), what would be a good alternative here without forcing the GUI to wait until the timeout is reached?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @TUStudi

      Setting timeout for QLabel-Text without Signals&Sots
      So i hav read that it is not recommendet to use a Thread.sleep(),

      That's because you should not use sleep() and you should use signals & slots. All you need to use here is a QTimer: set the text, set off the timer (singleShot() should do you), clear the text on timeout.

      T 1 Reply Last reply
      3
      • JonBJ JonB

        @TUStudi

        Setting timeout for QLabel-Text without Signals&Sots
        So i hav read that it is not recommendet to use a Thread.sleep(),

        That's because you should not use sleep() and you should use signals & slots. All you need to use here is a QTimer: set the text, set off the timer (singleShot() should do you), clear the text on timeout.

        T Offline
        T Offline
        TUStudi
        wrote on last edited by
        #3

        @JonB Thank you!

        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