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. qstackedwidget timeout
Qt 6.11 is out! See what's new in the release blog

qstackedwidget timeout

Scheduled Pinned Locked Moved Unsolved General and Desktop
qstackedwidget
6 Posts 3 Posters 2.7k Views 2 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.
  • W Offline
    W Offline
    WhatIf
    wrote on last edited by
    #1

    Hi,

    I created a qstackedwidget (3 pages) using qt designer. My goal is page 1 leads the user to page3. When the user clicks a button on page 1, page 2 will show a message for 10-15 seconds then the user is redirected to page 3. I can't figure out how to implement it nor can I find an example online I can study.

    Would appreciate your assistance!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You can use QTimer for that kind of task. What precisely do you have in mind ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by mrjj
        #3

        Hi
        you can use a timer which you connect to your slot.
        When you press button 1, you start timer and switch to page 2
        (showing the message)
        then when timer fires its timeout() signal, to your slot, then
        you simply go to page 3.

        W 2 Replies Last reply
        0
        • mrjjM mrjj

          Hi
          you can use a timer which you connect to your slot.
          When you press button 1, you start timer and switch to page 2
          (showing the message)
          then when timer fires its timeout() signal, to your slot, then
          you simply go to page 3.

          W Offline
          W Offline
          WhatIf
          wrote on last edited by
          #4

          @mrjj

          I'm just starting to learn Qt and get involved in C++ programming again. I followed your advise to the best of my ability but ran through an error.

          In mainwindow.h I added void move2page3();

          private slots:
              void on_pushButton_clicked();
              void move2page3();
          

          in mainwindow.cpp I added

          void MainWindow::on_pushButton_clicked()
          {
              QTimer::singleShot(200, this, SLOT(move2page3()));
          
              ui->stackedWidget->setCurrentIndex(1);
          }
          
          void MainWindow::move2page3()
          {
              ui->stackedWidget->setCurrentIndex(2);
          }
          

          When I try to run the app, I get the following error:

          C:\3pages\mainwindow.cpp:-1: In member function 'void MainWindow::on_pushButton_clicked()':

          C:\3pages\mainwindow.cpp:18: error: incomplete type 'QTimer' used in nested name specifier
          QTimer::singleShot(200, this, SLOT(move2page3()));
          ^

          First, am I following your advice or did I miss anything?
          Second, what am I doing wrong?

          1 Reply Last reply
          0
          • mrjjM mrjj

            Hi
            you can use a timer which you connect to your slot.
            When you press button 1, you start timer and switch to page 2
            (showing the message)
            then when timer fires its timeout() signal, to your slot, then
            you simply go to page 3.

            W Offline
            W Offline
            WhatIf
            wrote on last edited by
            #5

            @mrjj

            Okay, I was missing the #include <QTimer> in mainwindow.cpp and mainwindow.h

            It's now working, thanks :)

            Did I implement your advice the way you had in mind? Do you have any feedback?

            mrjjM 1 Reply Last reply
            0
            • W WhatIf

              @mrjj

              Okay, I was missing the #include <QTimer> in mainwindow.cpp and mainwindow.h

              It's now working, thanks :)

              Did I implement your advice the way you had in mind? Do you have any feedback?

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @WhatIf
              Hi
              Yes it was as i thought of.
              Even better actually as you found singleShot :)
              Only thing that I wondered was
              the singleShot(200) as 200 is very fast :)

              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