Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Obtain QPushButton created in .ui file from another class



  • I currently have three classes: Page1,Page2 and Page_stackedWidget. On Page1.ui I have a QPushButton along with other widgets. On Page_stackedWidget.ui I created a stackedwidget which I include Page1 and Page2 and when I run the program, it works correctly. However, I would like it so when I press a button that is in page 1 it takes me to page 2. This is what I have for Page_stackedWidget.cpp

    #include "page_stackedwidget.h"
    #include "ui_page_stackedwidget.h"
    
    Page_stackedWidget::Page_stackedWidget(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Dialog)
    }
    ui->setupUi(this);
    connect(Page1->nextButton, SIGNAL(clicked()),this,SLOT(goToPage2())); 
    }
    
    void Dialog::goToPage2()
    {
    ui->stackedWidget->setCurrentIndex(1);
    }
    

    However, the "nextButton" I created on the .ui file for Page1. I have looked for forums and i have found some similar to my problem but the difference is that their button is created on this file. http://stackoverflow.com/questions/9694474/manipulating-qt-ui-with-different-source-files.


  • Lifetime Qt Champion

    Hi,

    That question is already being answered here

    Let's keep it in only one place, closing this one.


Log in to reply