This article turned from: http://www.2cto.com/kf/201203/124441.html. QT Multi-window switching program layout in 1.ui files
2. Main program main.cpp
#include <QtGui/QApplication>
#include "mainwindow.h"
int main (int argc, char *argv[])
{
Qapplication A (argc, argv);
MainWindow W;
W.show ();
return a.exec ();
}
Main interface Program:
mainwindow.h
ifndef mainwindow_h
#define MAINWINDOW_H
#include <QMainWindow>
#include "Dialog1.h"
# Include "Dialog2.h"
namespace Ui {
class MainWindow;
}
Class Mainwindow:public Qmainwindow
{
q_object public
:
explicit MainWindow (Qwidget *parent = 0); C12/>~mainwindow ();
Private slots:
void on_pushbutton_clicked ();
void on_pushbutton_2_clicked ();
void on_pushbutton_3_clicked ();
Private:
Ui::mainwindow *ui;
Dialog1 Dialog1;
Dialog2 dialog2;
};
#endif//Mainwindow_h
Mainwindow.cpp
"> #include" mainwindow.h "
#include" ui_mainwindow.h "
Mainwindow::mainwindow (Qwidget *parent):
Qmainwindow (parent),
UI (new Ui::mainwindow)
{
ui->setupui (this);
}
Mainwindow::~mainwindow ()
{
delete ui;
}
void mainwindow::on_pushbutton_clicked ()
{
this->hide ();
Dialog1.show ();
Dialog1.exec ();
This->show ();
}
void mainwindow::on_pushbutton_2_clicked ()
{
this->close ();
}
void mainwindow::on_pushbutton_3_clicked ()
{
this->close ();
Dialog2.show ();
Dialog2.exec ();
This->show ();
}
Dialog1.cpp
#include "dialog1.h"
#include "Ui_dialog1.h"
Dialog1::D ialog1 (Qwidget *parent):
qdialog (parent),
UI (New UI::D ialog1)
{
ui->setupui (this);
}
Dialog1::~dialog1 ()
{
delete ui;
}
void dialog1::on_pushbutton_clicked ()
{
this->close ();
}
Dialog2.cpp is similar to Dialog1
Key points:
This->close ();
Dialog2.show ();
Dialog2.exec ();
This->show ();
determine if the main interface is echoing by waiting for the dialog.exec () message. Operation Result: