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. How to display Label for 30 seconds and then hide it?
Forum Updated to NodeBB v4.3 + New Features

How to display Label for 30 seconds and then hide it?

Scheduled Pinned Locked Moved Solved Mobile and Embedded
32 Posts 8 Posters 20.6k Views 3 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.
  • MijazM Offline
    MijazM Offline
    Mijaz
    wrote on last edited by
    #20

    ui->lbl->setVisible(true); before setText

    QTimer::singleShot(1000, ui->lbl, &QLabel::hide);

    above command just hide the text after 1 second but never blink again.
    I want to blink my lbl text continuously until I click to stop button. so how it possible. guide, please me.

    This is the code in my case

    void secBox::on_APush_clicked()
    {
    // need start fleshing

    ui->flashing_text->setVisible(true);
    QTimer::singleShot(1000, ui->flashing_text, &QLabel::hide);
    //QTimer::singleShot(1000, ui->flashing_text, &QLabel::show); // this does not works
    

    }

    void secBox::on_BPush_clicked()
    {
    // need stop fleshing

    }

    jsulmJ 1 Reply Last reply
    0
    • MijazM Mijaz

      ui->lbl->setVisible(true); before setText

      QTimer::singleShot(1000, ui->lbl, &QLabel::hide);

      above command just hide the text after 1 second but never blink again.
      I want to blink my lbl text continuously until I click to stop button. so how it possible. guide, please me.

      This is the code in my case

      void secBox::on_APush_clicked()
      {
      // need start fleshing

      ui->flashing_text->setVisible(true);
      QTimer::singleShot(1000, ui->flashing_text, &QLabel::hide);
      //QTimer::singleShot(1000, ui->flashing_text, &QLabel::show); // this does not works
      

      }

      void secBox::on_BPush_clicked()
      {
      // need stop fleshing

      }

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #21

      @Mijaz If you want the label blinking then don't use singleShot - as the name says it just fires once.
      Create a QTimer instance, set interval and connect a slot to https://doc.qt.io/qt-5/qtimer.html#timeout

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      MijazM 2 Replies Last reply
      1
      • jsulmJ jsulm

        @Mijaz If you want the label blinking then don't use singleShot - as the name says it just fires once.
        Create a QTimer instance, set interval and connect a slot to https://doc.qt.io/qt-5/qtimer.html#timeout

        MijazM Offline
        MijazM Offline
        Mijaz
        wrote on last edited by
        #22

        @jsulm
        thanks !
        Will you send me an example where this function used, because I am unable to use it.

        jsulmJ 1 Reply Last reply
        0
        • jsulmJ jsulm

          @Mijaz If you want the label blinking then don't use singleShot - as the name says it just fires once.
          Create a QTimer instance, set interval and connect a slot to https://doc.qt.io/qt-5/qtimer.html#timeout

          MijazM Offline
          MijazM Offline
          Mijaz
          wrote on last edited by
          #23

          @jsulm
          I my case, I tried to implement this but it shows error.

          aha_1980A 1 Reply Last reply
          0
          • MijazM Mijaz

            @jsulm
            I my case, I tried to implement this but it shows error.

            aha_1980A Offline
            aha_1980A Offline
            aha_1980
            Lifetime Qt Champion
            wrote on last edited by
            #24

            @Mijaz said in How to display Label for 30 seconds and then hide it?:

            I my case, I tried to implement this but it shows error.

            Which error exactly? Please show your code.

            Regards

            Qt has to stay free or it will die.

            MijazM 1 Reply Last reply
            0
            • MijazM Mijaz

              @jsulm
              thanks !
              Will you send me an example where this function used, because I am unable to use it.

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #25

              @Mijaz said in How to display Label for 30 seconds and then hide it?:

              Will you send me an example

              No, because there are already examples (you can find them in the link I sent you before):
              See also QBasicTimer, QTimerEvent, QObject::timerEvent(), Timers, Analog Clock Example, and Wiggly Example.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • aha_1980A aha_1980

                @Mijaz said in How to display Label for 30 seconds and then hide it?:

                I my case, I tried to implement this but it shows error.

                Which error exactly? Please show your code.

                Regards

                MijazM Offline
                MijazM Offline
                Mijaz
                wrote on last edited by
                #26

                @aha_1980
                errr.png

                aha_1980A JonBJ 2 Replies Last reply
                0
                • MijazM Mijaz

                  @aha_1980
                  errr.png

                  aha_1980A Offline
                  aha_1980A Offline
                  aha_1980
                  Lifetime Qt Champion
                  wrote on last edited by
                  #27

                  @Mijaz

                  You create a new timer everytime your slot on_APush_clicked() is called. Make the timer a member variable and create it once.

                  timer->start() without parameters should work.

                  Then the only needed step is to create a slot that does whatever you want.

                  Regards

                  Qt has to stay free or it will die.

                  MijazM 1 Reply Last reply
                  2
                  • MijazM Mijaz

                    @aha_1980
                    errr.png

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

                    @Mijaz

                    connect(..., ui->flashing_text->setText("..."));
                    

                    The last parameter to connect()must be either a function/method or a lambda, which in turn will execute the setText() you show. You cannot have it be the actual function call you are trying. This is the cause of the error message you see.

                    It would help you if you read up on Qt signals & slots, https://doc.qt.io/qt-5/signalsandslots.html.

                    1 Reply Last reply
                    4
                    • aha_1980A aha_1980

                      @Mijaz

                      You create a new timer everytime your slot on_APush_clicked() is called. Make the timer a member variable and create it once.

                      timer->start() without parameters should work.

                      Then the only needed step is to create a slot that does whatever you want.

                      Regards

                      MijazM Offline
                      MijazM Offline
                      Mijaz
                      wrote on last edited by
                      #29

                      @aha_1980
                      eeeer.png
                      I have created new simple project. it shows all ok but still not blinking.

                      jsulmJ 1 Reply Last reply
                      0
                      • MijazM Mijaz

                        @aha_1980
                        eeeer.png
                        I have created new simple project. it shows all ok but still not blinking.

                        jsulmJ Offline
                        jsulmJ Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on last edited by jsulm
                        #30

                        @Mijaz In the screen-shot you posted you still call singleShot!
                        Did you read the link I posted? There are even examples:

                        QTimer *timer = new QTimer(this);
                        connect(timer, &QTimer::timeout, this, QOverload<>::of(&AnalogClock::update));
                        timer->start(1000);
                        

                        Just connect your own slot to timeout and in that slot toggle the label...

                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        2
                        • MhM93M MhM93

                          this is runread function :

                          MainWindow::MainWindow(QWidget *parent) :
                              QMainWindow(parent),
                              ui(new Ui::MainWindow)
                          {
                              ui->setupUi(this);
                              ui->statusBar->addWidget(ui->label,0);
                              ui->label->setText("the status of device");
                              ui->lbl_welcome->hide();
                              //QTimer::singleShot(2000,ui->lbl_welcome,SLOT(hide()));
                          
                              QtConcurrent::run(this,&MainWindow::runread);
                              //-----------------------
                          
                          }
                          
                          void MainWindow::runread()
                          {
                              //-----------------------
                              fd=-1;
                              db = QSqlDatabase::addDatabase("QSQLITE");//not dbConnection
                              QString path = "VirtualDB";
                              db.setDatabaseName(path);
                          
                              if(!db.open())
                              {
                                  ui->label->setText("Error to open database");
                              }
                              else
                              {
                                  QSqlQuery q;
                                  q.exec("create table IF NOT EXISTS Absent(card varchar(20) , "
                                                          "DateTime varchar(50));");
                                  while(fd==-1)
                                  {
                                      openport();
                          
                                      if (fd!=-1)
                                      {
                                          configport();
                                          ui->label->setText(" open port");
                                          ui->label->setText("  Put your card please: ");
                          
                                          if(fd!=-1)
                                          {
                                              for(int i=0;i<100;i++)
                                              {
                                                   if ((numbytes = read(fd,buf2, MAXDATASIZE)) != -1)
                                                   {
                                                       ui->label->setText(" read card");
                          
                                                      buf2[numbytes] = '\0';
                                                      usleep(10000);
                                                      QString s1(buf2);
                                                      memset(buf2,'\0',MAXDATASIZE);
                                                      read(fd,buf2, MAXDATASIZE-1) ;
                                                      QString s2(buf2);
                                                      memset(buf2,'\0',MAXDATASIZE);
                                                      string card=(s1+s2).toStdString();
                                                      QString dt=QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss");
                                                      
                                                      q.prepare("insert into Absent(card,DateTime) values(?,?);");
                                                      q.bindValue(0,card.c_str());
                                                      q.bindValue(1,dt);
                                                      if(!q.exec())
                                                          qDebug()<<q.lastError();
                                                      string result=(" WELL COME ");
                                                      
                                                      ui->lbl_welcome->show();
                          //                            QTimer::singleShot(30000, ui->lbl_welcome,&QLabel::hide);
                                                      //QTimer::singleShot(2000,ui->lbl_welcome,SLOT(hide()));
                                                      hide();
                          
                                                   }
                                                   else
                                                   {
                                                       if(TransferDatatoUSB())
                                                       {
                                                           QString filename="save.txt";
                                                           QFile file( filename );
                          
                                                          
                                                           q.exec("select card,DateTime from Absent;");
                          
                                                               CreateFile();
                                                               if ( file.open(QIODevice::ReadWrite) )
                                                               {
                                                                   QTextStream stream( &file );
                                                                   while (q.next()) {
                                                                       QString str=q.value(0).toString();
                                                                       str.append("     ");
                                                                       str.append(q.value(1).toString());
                                                                       str.append(" ");
                                                                       //o <<str.toStdString();
                                                                       stream << str << endl;
                                                               }
                                                           }
                                                           CopyToUSB();
                                                       }
                          
                                                   }
                                              }
                                          }
                                      }
                                  }
                              }
                          
                          }
                          
                          // I do this instead of QTimer but I thinck it is not true.(but it works)
                          void MainWindow::hide()
                          {
                              //QTimer::singleShot(2000,ui->lbl_welcome,SLOT(hide()));
                              sleep(2);
                              ui->lbl_welcome->hide();
                          }
                          
                          R Offline
                          R Offline
                          RAJALINGAM
                          wrote on last edited by
                          #31

                          @MhM93
                          thank you...

                          R 1 Reply Last reply
                          0
                          • R RAJALINGAM

                            @MhM93
                            thank you...

                            R Offline
                            R Offline
                            RAJALINGAM
                            wrote on last edited by
                            #32

                            @RAJALINGAM
                            can you please share your form window

                            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