好吧,我想要做2个Windows应用程序(1个窗口有一个在上一个窗口中打开第二个窗口的按钮)
到目前为止,我已经知道了:
login.h
class MainWindow2: public QWidget
{
Q_OBJECT
public:
explicit MainWindow2(QWidget *parent = nullptr);
~MainWindow2();
private:
MainWindow2 *ui;
};
login.cpp
MainWindow2::MainWindow2(QWidget *parent) : QWidget(parent), ui(new MainWindow2)
{
ui->setupUi(this);
}
MainWindow2::~MainWindow2()
{
delete ui;
}
确切地说,我在login.cpp中遇到错误,错误是“ MainWindow2中没有名为setupUi的成员”
.pro file
#-------------------------------------------------
#
# Project created by QtCreator 2019-06-21T16:44:15
#
#-------------------------------------------------
QT += core gui network
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = untitled3
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
CONFIG += c++11
SOURCES += \
login.cpp \
main.cpp \
mainwindow.cpp
HEADERS += \
login.h \
mainwindow.h
FORMS += \
login.ui \
mainwindow.ui
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
答案 0 :(得分:0)
首先,在Qt Creator 5.8中,您需要将表单添加到项目(* .pro)中: add new form to Qt 然后在第一个表格标题中包含第二个表格标题。然后,您可以以第一种形式
声明和初始化第二种形式的指针类型Form2 m_pSecondWnd = new Form
在第一种形式的按钮点击位置上,您可以调用:
this->close();
m_pSecondWnd ->show();
答案 1 :(得分:0)
诸如仅创建唯一的QT导致的错误,例如“在“类” 中没有名为setupUi的成员”或“分配不完整类型“ UI :: class” ”的错误表单设计器(QT设计器未创建.h文件,仅创建.ui)。您要做的是:创建QT设计器形式的类,以创建.h和.ui文件。并且不要忘记按照以下方式#include它:例如,#include“ ui_mainwindow.h”。编码愉快!