qstackedwidget timeout



  • 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!


  • Lifetime Qt Champion

    Hi,

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


  • Qt Champions 2016

    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.



  • @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?



  • @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?


  • Qt Champions 2016

    @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 :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.