简体   繁体   中英

QT open a form(.ui) from main form by button push

I have searched many forums to solve this problem so please don't just link a forum.

I have my main.ui that is loaded at the start. it's header

using namespace Ui;
class main: public QMainWindow
{
    Q_OBJECT

public slots:
    void AddPlayer();

public:
    main(QWidget *parent = 0);
   ~main();

private:
    Ui::mainClass ui;
    Ui::FormPla uiPlayer;//the name of the form i want to open
};

Then i have the main.cpp

main::main(QWidget *parent)
    : QMainWindow(parent)
{
     ui.setupUi(this);
     connect(ui.mainBtnPla, SIGNAL(clicked()), SLOT(AddPlayer()));
}
main::~main()
{
}
void FinalYearProject::AddPlayer() 
{
    //code to open player.ui

    //formPla *obj;
    //obj = new formPla();
    //obj->show(); //i tried this but show wasnt a member of ui::player

}

player.ui doesnt have a .h or .cpp. I dont know if this affects this. I just want to be able open the form.

ui generated classes cannot be used without a QWidget class loading them.

You must create a separate QWidget base class (Player), loading Ui::FormPla and later create an instance of this class to show the Ui::FormPla on screen.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM