[英]Controlling Multiple UI files in Qt framework
Question asked twice: see Handling multiple ui files in Qt 问了两次问题:请参阅在Qt中处理多个ui文件
I am new to Qt framwork , i have been given this simple task: 我是Qt框架的新手,我得到了以下简单任务:
In the MainWindow , i have a submit button , once its clicked another total different window should appear 在MainWindow中,我有一个Submit按钮,一旦单击它,应该会出现另一个完全不同的窗口
i thought of doing this by doing one extra UI file called From.ui file and to switch from MainWindow to Form once submit is clicked , this is my code: 我想通过做一个额外的UI文件From.ui文件来做到这一点,并在单击提交后从MainWindow切换到Form,这是我的代码:
//main.cpp
#include "mainwindow.h"
#include <QtGui/QApplication>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MainWindow mainWindow;
mainWindow.setOrientation(MainWindow::ScreenOrientationAuto);
mainWindow.showExpanded();
return app.exec();
}
//MainWindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "form.h"
#include <QtCore/QCoreApplication>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow:: SubmitClicked()
{
Form* f= new Form(this);
f->show();
f->raise();
f->activateWindow();
}
//Form.cpp
#include "form.h"
#include "ui_form.h"
Form::Form(QWidget *parent) :
QWidget(parent),
ui(new Ui::Form)
{
ui->setupUi(this);
}
Form::~Form()
{
delete ui;
}
this code compiled perfectly , but its not doing as expected , once submit is clicked , nothing is done... 该代码完美地编译,但是没有按预期方式运行,一旦单击提交,就什么也没做...
can you please tell me whats wrong ? 你能告诉我怎么了吗?
It seems that SubmitClicked slot is not connected to clicked event of your button 似乎SubmitClicked插槽未与按钮的clicked事件连接
Put a cout/printf at the top of your SubmitClicked method to make sure that it is called. 将cout / printf放在SubmitClicked方法的顶部,以确保已调用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.