Far*_*had 11
首先使用 Qt 创建一个新项目,然后右键单击项目名称 -> Add new... 并创建一个新的 UI 类,如下图:
,

现在你有两种形式。您需要从 First 中的 Second class 制作一个对象。
第一个.h
#ifndef FIRST_H
#define FIRST_H
#include <QMainWindow>
#include <second.h>
#include <QTimer>
namespace Ui {
class First;
}
class First : public QMainWindow
{
Q_OBJECT
public:
explicit First(QWidget *parent = 0);
~First();
private slots:
void on_pushButton_clicked();
void changeWindow();
private:
Ui::First *ui;
Second *second;
QTimer * timer;
};
#endif // FIRST_H
Run Code Online (Sandbox Code Playgroud)
第一个.cpp
#include "first.h"
#include "ui_first.h"
First::First(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::First)
{
ui->setupUi(this);
second = new Second();
timer = new QTimer();
connect(timer,&QTimer::timeout,this,&First::changeWindow);
timer->start(1000); // 1000 ms
}
First::~First()
{
delete ui;
}
void First::changeWindow()
{
if(second->isVisible())
{
second->hide();
this->show();
}
else
{
this->hide();
second->show();
}
}
void First::on_pushButton_clicked()
{
second->show();
}
Run Code Online (Sandbox Code Playgroud)
第一版
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = First
TEMPLATE = app
SOURCES += main.cpp\
first.cpp \
second.cpp
HEADERS += first.h \
second.h
FORMS += first.ui \
second.ui
Run Code Online (Sandbox Code Playgroud)