热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

具有Qt4的C的多窗口

我正在尝试构建一个GUI应用程序,我正在通过Qt这样做.我还想创建一个多窗口应用程序:我希望当我按下一个按钮时,另一个窗口显示(“隐藏”前一个窗口).那是GDI吗?到目前为止,我已

我正在尝试构建一个GUI应用程序,我正在通过Qt这样做.我还想创建一个多窗口应用程序:我希望当我按下一个按钮时,另一个窗口显示(“隐藏”前一个窗口).那是GDI吗?

到目前为止,我已经为我想要的每个窗口(当前为4)创建了一个.ui文件,并且我正在尝试以这种方式连接它们(主窗口,另外3个).

我怎么能这样做?

我正在发送该程序的文件,以使我的问题更加不可靠:

main.cpp中

#include
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
StudyWindow s;
QStackedWidget *stackedWidget = new QStackedWidget;
stackedWidget->addWidget(w);
stackedWidget->addWidget(s);
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(stackedWidget);
setLayout(layout);
w.show();
return a.exec();
}

mainwindow.cpp

#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ConnectStuff();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::ConnectStuff()
{
}

mainwindow.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include
#include
#include
#include
#include "study.h"
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
void ConnectStuff();
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H

study.h

#ifndef STUDYWINDOW_H
#define STUDYWINDOW_H
#include
#include
namespace Ui {
class StudyWindow;
}
class StudyWindow : public QMainWindow
{
Q_OBJECT
public:
explicit StudyWindow(QWidget *parent = 0);
~StudyWindow();
private:
Ui::StudyWindow *ui;
};
#endif // STUDYWINDOW_H

ui_Study.h

/********************************************************************************
** Form generated from reading UI file 'Study.ui'
**
** Created: Tue 20. Mar 20:10:56 2012
** by: Qt User Interface Compiler version 4.7.4
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/
#ifndef UI_STUDY_H
#define UI_STUDY_H
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
QT_BEGIN_NAMESPACE
class Ui_StudyWindow
{
public:
QAction *actionVoltar;
QAction *actionSair;
QWidget *centralwidget;
QTreeWidget *treeWidget;
QPushButton *pushButton;
QMenuBar *menubar;
QMenu *menuVoltar;
QStatusBar *statusbar;
void setupUi(QMainWindow *MainWindow)
{
if (MainWindow->objectName().isEmpty())
MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
MainWindow->resize(800, 600);
actiOnVoltar= new QAction(MainWindow);
actionVoltar->setObjectName(QString::fromUtf8("actionVoltar"));
actiOnSair= new QAction(MainWindow);
actionSair->setObjectName(QString::fromUtf8("actionSair"));
centralwidget = new QWidget(MainWindow);
centralwidget->setObjectName(QString::fromUtf8("centralwidget"));
treeWidget = new QTreeWidget(centralwidget);
QFont font;
font.setPointSize(8);
font.setBold(true);
font.setWeight(75);
QTreeWidgetItem *__qtreewidgetitem = new QTreeWidgetItem();
__qtreewidgetitem->setFont(0, font);
treeWidget->setHeaderItem(__qtreewidgetitem);
new QTreeWidgetItem(treeWidget);
new QTreeWidgetItem(treeWidget);
new QTreeWidgetItem(treeWidget);
new QTreeWidgetItem(treeWidget);
new QTreeWidgetItem(treeWidget);
new QTreeWidgetItem(treeWidget);
new QTreeWidgetItem(treeWidget);
new QTreeWidgetItem(treeWidget);
new QTreeWidgetItem(treeWidget);
new QTreeWidgetItem(treeWidget);
treeWidget->setObjectName(QString::fromUtf8("treeWidget"));
treeWidget->setGeometry(QRect(0, 110, 161, 451));
pushButton = new QPushButton(centralwidget);
pushButton->setObjectName(QString::fromUtf8("pushButton"));
pushButton->setGeometry(QRect(0, 0, 75, 23));
MainWindow->setCentralWidget(centralwidget);
menubar = new QMenuBar(MainWindow);
menubar->setObjectName(QString::fromUtf8("menubar"));
menubar->setGeometry(QRect(0, 0, 800, 21));
menuVoltar = new QMenu(menubar);
menuVoltar->setObjectName(QString::fromUtf8("menuVoltar"));
MainWindow->setMenuBar(menubar);
statusbar = new QStatusBar(MainWindow);
statusbar->setObjectName(QString::fromUtf8("statusbar"));
MainWindow->setStatusBar(statusbar);
menubar->addAction(menuVoltar->menuAction());
menuVoltar->addAction(actionVoltar);
menuVoltar->addSeparator();
menuVoltar->addAction(actionSair);
retranslateUi(MainWindow);
QMetaObject::connectSlotsByName(MainWindow);
} // setupUi
void retranslateUi(QMainWindow *MainWindow)
{
MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", 0, QApplication::UnicodeUTF8));
actionVoltar->setText(QApplication::translate("MainWindow", "Voltar", 0, QApplication::UnicodeUTF8));
actionSair->setText(QApplication::translate("MainWindow", "Sair", 0, QApplication::UnicodeUTF8));
QTreeWidgetItem *___qtreewidgetitem = treeWidget->headerItem();
___qtreewidgetitem->setText(1, QApplication::translate("MainWindow", "Items", 0, QApplication::UnicodeUTF8));
___qtreewidgetitem->setText(0, QApplication::translate("MainWindow", "Mat\303\251ria", 0, QApplication::UnicodeUTF8));
const bool __sortingEnabled = treeWidget->isSortingEnabled();
treeWidget->setSortingEnabled(false);
QTreeWidgetItem *___qtreewidgetitem1 = treeWidget->topLevelItem(0);
___qtreewidgetitem1->setText(0, QApplication::translate("MainWindow", "Portugu\303\252s", 0, QApplication::UnicodeUTF8));
QTreeWidgetItem *___qtreewidgetitem2 = treeWidget->topLevelItem(1);
___qtreewidgetitem2->setText(0, QApplication::translate("MainWindow", "Reda\303\247\303\243o", 0, QApplication::UnicodeUTF8));
QTreeWidgetItem *___qtreewidgetitem3 = treeWidget->topLevelItem(2);
___qtreewidgetitem3->setText(0, QApplication::translate("MainWindow", "Matem\303\241tica", 0, QApplication::UnicodeUTF8));
QTreeWidgetItem *___qtreewidgetitem4 = treeWidget->topLevelItem(3);
___qtreewidgetitem4->setText(0, QApplication::translate("MainWindow", "Biologia", 0, QApplication::UnicodeUTF8));
QTreeWidgetItem *___qtreewidgetitem5 = treeWidget->topLevelItem(4);
___qtreewidgetitem5->setText(0, QApplication::translate("MainWindow", "F\303\255sica", 0, QApplication::UnicodeUTF8));
QTreeWidgetItem *___qtreewidgetitem6 = treeWidget->topLevelItem(5);
___qtreewidgetitem6->setText(0, QApplication::translate("MainWindow", "Qu\303\255mica", 0, QApplication::UnicodeUTF8));
QTreeWidgetItem *___qtreewidgetitem7 = treeWidget->topLevelItem(6);
___qtreewidgetitem7->setText(0, QApplication::translate("MainWindow", "Hist\303\263ria", 0, QApplication::UnicodeUTF8));
QTreeWidgetItem *___qtreewidgetitem8 = treeWidget->topLevelItem(7);
___qtreewidgetitem8->setText(0, QApplication::translate("MainWindow", "Geografia", 0, QApplication::UnicodeUTF8));
QTreeWidgetItem *___qtreewidgetitem9 = treeWidget->topLevelItem(8);
___qtreewidgetitem9->setText(0, QApplication::translate("MainWindow", "Ingl\303\252s", 0, QApplication::UnicodeUTF8));
QTreeWidgetItem *___qtreewidgetitem10 = treeWidget->topLevelItem(9);
___qtreewidgetitem10->setText(0, QApplication::translate("MainWindow", "Espanhol", 0, QApplication::UnicodeUTF8));
treeWidget->setSortingEnabled(__sortingEnabled);
pushButton->setText(QApplication::translate("MainWindow", "Cansei!", 0, QApplication::UnicodeUTF8));
menuVoltar->setTitle(QApplication::translate("MainWindow", "Arquivo", 0, QApplication::UnicodeUTF8));
} // retranslateUi
};
namespace Ui {
class StudyWindow: public Ui_StudyWindow {};
} // namespace Ui
QT_END_NAMESPACE
#endif // UI_STUDY_H

ui_mainwindow.h

/********************************************************************************
** Form generated from reading UI file 'mainwindow.ui'
**
** Created: Tue 20. Mar 20:10:56 2012
** by: Qt User Interface Compiler version 4.7.4
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/
#ifndef UI_MAINWINDOW_H
#define UI_MAINWINDOW_H
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
QT_BEGIN_NAMESPACE
class Ui_MainWindow
{
public slots:
public:
QAction *actionAjuda;
QAction *actionLista_de;
QAction *actionSair;
QWidget *centralwidget;
QPushButton *pshBStudy;
QPushButton *pshBSimulator;
QPushButton *pshBExamCalen;
QPushButton *pshBReadOfDay;
QLabel *labelTitle;
QPlainTextEdit *plainTextNews;
QLabel *labelNews;
QGroupBox *groupBox;
QLabel *labelCollege;
QLabel *labelCourse;
QLabel *labelMemSince;
QLabel *labelLoggedWith;
QLabel *labelBP;
QStatusBar *statusbar;
QMenuBar *menuBar;
QMenu *menuArquivo;
void setupUi(QMainWindow *MainWindow)
{
if (MainWindow->objectName().isEmpty())
MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
MainWindow->resize(800, 600);
QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(MainWindow->sizePolicy().hasHeightForWidth());
MainWindow->setSizePolicy(sizePolicy);
actiOnAjuda= new QAction(MainWindow);
actionAjuda->setObjectName(QString::fromUtf8("actionAjuda"));
actionLista_de = new QAction(MainWindow);
actionLista_de->setObjectName(QString::fromUtf8("actionLista_de"));
actiOnSair= new QAction(MainWindow);
actionSair->setObjectName(QString::fromUtf8("actionSair"));
centralwidget = new QWidget(MainWindow);
centralwidget->setObjectName(QString::fromUtf8("centralwidget"));
pshBStudy = new QPushButton(centralwidget);
pshBStudy->setObjectName(QString::fromUtf8("pshBStudy"));
pshBStudy->setGeometry(QRect(140, 120, 161, 81));
pshBStudy->setDefault(true);
pshBSimulator = new QPushButton(centralwidget);
pshBSimulator->setObjectName(QString::fromUtf8("pshBSimulator"));
pshBSimulator->setGeometry(QRect(530, 120, 161, 81));
pshBExamCalen = new QPushButton(centralwidget);
pshBExamCalen->setObjectName(QString::fromUtf8("pshBExamCalen"));
pshBExamCalen->setGeometry(QRect(140, 260, 161, 81));
pshBReadOfDay = new QPushButton(centralwidget);
pshBReadOfDay->setObjectName(QString::fromUtf8("pshBReadOfDay"));
pshBReadOfDay->setGeometry(QRect(530, 260, 161, 81));
labelTitle = new QLabel(centralwidget);
labelTitle->setObjectName(QString::fromUtf8("labelTitle"));
labelTitle->setGeometry(QRect(200, 10, 431, 71));
QFont font;
font.setPointSize(23);
labelTitle->setFont(font);
plainTextNews = new QPlainTextEdit(centralwidget);
plainTextNews->setObjectName(QString::fromUtf8("plainTextNews"));
plainTextNews->setGeometry(QRect(610, 440, 181, 111));
plainTextNews->setReadOnly(true);
labelNews = new QLabel(centralwidget);
labelNews->setObjectName(QString::fromUtf8("labelNews"));
labelNews->setGeometry(QRect(610, 420, 81, 16));
groupBox = new QGroupBox(centralwidget);
groupBox->setObjectName(QString::fromUtf8("groupBox"));
groupBox->setGeometry(QRect(0, 460, 431, 91));
labelCollege = new QLabel(groupBox);
labelCollege->setObjectName(QString::fromUtf8("labelCollege"));
labelCollege->setGeometry(QRect(230, 50, 111, 16));
labelCourse = new QLabel(groupBox);
labelCourse->setObjectName(QString::fromUtf8("labelCourse"));
labelCourse->setGeometry(QRect(230, 30, 111, 16));
labelMemSince = new QLabel(groupBox);
labelMemSince->setObjectName(QString::fromUtf8("labelMemSince"));
labelMemSince->setGeometry(QRect(10, 50, 111, 16));
labelLoggedWith = new QLabel(groupBox);
labelLoggedWith->setObjectName(QString::fromUtf8("labelLoggedWith"));
labelLoggedWith->setGeometry(QRect(10, 30, 111, 16));
labelBP = new QLabel(groupBox);
labelBP->setObjectName(QString::fromUtf8("labelBP"));
labelBP->setGeometry(QRect(10, 70, 111, 16));
MainWindow->setCentralWidget(centralwidget);
statusbar = new QStatusBar(MainWindow);
statusbar->setObjectName(QString::fromUtf8("statusbar"));
MainWindow->setStatusBar(statusbar);
menuBar = new QMenuBar(MainWindow);
menuBar->setObjectName(QString::fromUtf8("menuBar"));
menuBar->setGeometry(QRect(0, 0, 800, 21));
menuArquivo = new QMenu(menuBar);
menuArquivo->setObjectName(QString::fromUtf8("menuArquivo"));
MainWindow->setMenuBar(menuBar);
QWidget::setTabOrder(pshBStudy, pshBSimulator);
QWidget::setTabOrder(pshBSimulator, pshBExamCalen);
QWidget::setTabOrder(pshBExamCalen, pshBReadOfDay);
QWidget::setTabOrder(pshBReadOfDay, plainTextNews);
menuBar->addAction(menuArquivo->menuAction());
menuArquivo->addAction(actionSair);
retranslateUi(MainWindow);
QMetaObject::connectSlotsByName(MainWindow);
} // setupUi
void retranslateUi(QMainWindow *MainWindow)
{
MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", 0, QApplication::UnicodeUTF8));
actionAjuda->setText(QApplication::translate("MainWindow", "Sobre...", 0, QApplication::UnicodeUTF8));
actionLista_de->setText(QApplication::translate("MainWindow", "Lista de Provas", 0, QApplication::UnicodeUTF8));
actionSair->setText(QApplication::translate("MainWindow", "Sair...", 0, QApplication::UnicodeUTF8));
pshBStudy->setText(QApplication::translate("MainWindow", "Estudar!", 0, QApplication::UnicodeUTF8));
pshBSimulator->setText(QApplication::translate("MainWindow", "Simulado", 0, QApplication::UnicodeUTF8));
pshBExamCalen->setText(QApplication::translate("MainWindow", "Calend\303\241rio de Provas", 0, QApplication::UnicodeUTF8));
pshBReadOfDay->setText(QApplication::translate("MainWindow", "Leitura do Dia", 0, QApplication::UnicodeUTF8));
labelTitle->setText(QApplication::translate("MainWindow", "Escolha o que quer fazer hoje: ", 0, QApplication::UnicodeUTF8));
labelNews->setText(QApplication::translate("MainWindow", "Novidades:", 0, QApplication::UnicodeUTF8));
groupBox->setTitle(QApplication::translate("MainWindow", "Informa\303\247\303\265es", 0, QApplication::UnicodeUTF8));
labelCollege->setText(QApplication::translate("MainWindow", "Faculdade:", 0, QApplication::UnicodeUTF8));
labelCourse->setText(QApplication::translate("MainWindow", "Curso Pretendido:", 0, QApplication::UnicodeUTF8));
labelMemSince->setText(QApplication::translate("MainWindow", "Membro desde:", 0, QApplication::UnicodeUTF8));
labelLoggedWith->setText(QApplication::translate("MainWindow", "Voc\303\252 esta logado com: ", 0, QApplication::UnicodeUTF8));
labelBP->setText(QApplication::translate("MainWindow", "BP: ", 0, QApplication::UnicodeUTF8));
menuArquivo->setTitle(QApplication::translate("MainWindow", "Arquivo", 0, QApplication::UnicodeUTF8));
} // retranslateUi
};
namespace Ui {
class MainWindow: public Ui_MainWindow {};
} // namespace Ui
QT_END_NAMESPACE
#endif // UI_MAINWINDOW_H

解决方法:

您可以使用信号和插槽机制,为此请查看以下文档..

http://qt-project.org/doc/qt-4.8/signalsandslots.html

现在,您可以将一个窗口的信号连接到另一个窗口,并在另一个窗口的插槽中显示另一个窗口并隐藏前一个窗口.


推荐阅读
  • android listview OnItemClickListener失效原因
    最近在做listview时发现OnItemClickListener失效的问题,经过查找发现是因为button的原因。不仅listitem中存在button会影响OnItemClickListener事件的失效,还会导致单击后listview每个item的背景改变,使得item中的所有有关焦点的事件都失效。本文给出了一个范例来说明这种情况,并提供了解决方法。 ... [详细]
  • XML介绍与使用的概述及标签规则
    本文介绍了XML的基本概念和用途,包括XML的可扩展性和标签的自定义特性。同时还详细解释了XML标签的规则,包括标签的尖括号和合法标识符的组成,标签必须成对出现的原则以及特殊标签的使用方法。通过本文的阅读,读者可以对XML的基本知识有一个全面的了解。 ... [详细]
  • 本文介绍了三种方法来实现在Win7系统中显示桌面的快捷方式,包括使用任务栏快速启动栏、运行命令和自己创建快捷方式的方法。具体操作步骤详细说明,并提供了保存图标的路径,方便以后使用。 ... [详细]
  • Android系统移植与调试之如何修改Android设备状态条上音量加减键在横竖屏切换的时候的显示于隐藏
    本文介绍了如何修改Android设备状态条上音量加减键在横竖屏切换时的显示与隐藏。通过修改系统文件system_bar.xml实现了该功能,并分享了解决思路和经验。 ... [详细]
  • 本文介绍了Android 7的学习笔记总结,包括最新的移动架构视频、大厂安卓面试真题和项目实战源码讲义。同时还分享了开源的完整内容,并提醒读者在使用FileProvider适配时要注意不同模块的AndroidManfiest.xml中配置的xml文件名必须不同,否则会出现问题。 ... [详细]
  • C++字符字符串处理及字符集编码方案
    本文介绍了C++中字符字符串处理的问题,并详细解释了字符集编码方案,包括UNICODE、Windows apps采用的UTF-16编码、ASCII、SBCS和DBCS编码方案。同时说明了ANSI C标准和Windows中的字符/字符串数据类型实现。文章还提到了在编译时需要定义UNICODE宏以支持unicode编码,否则将使用windows code page编译。最后,给出了相关的头文件和数据类型定义。 ... [详细]
  • Go GUIlxn/walk 学习3.菜单栏和工具栏的具体实现
    本文介绍了使用Go语言的GUI库lxn/walk实现菜单栏和工具栏的具体方法,包括消息窗口的产生、文件放置动作响应和提示框的应用。部分代码来自上一篇博客和lxn/walk官方示例。文章提供了学习GUI开发的实际案例和代码示例。 ... [详细]
  • 本文介绍了如何清除Eclipse中SVN用户的设置。首先需要查看使用的SVN接口,然后根据接口类型找到相应的目录并删除相关文件。最后使用SVN更新或提交来应用更改。 ... [详细]
  • 本文详细介绍了Android中的坐标系以及与View相关的方法。首先介绍了Android坐标系和视图坐标系的概念,并通过图示进行了解释。接着提到了View的大小可以超过手机屏幕,并且只有在手机屏幕内才能看到。最后,作者表示将在后续文章中继续探讨与View相关的内容。 ... [详细]
  • 带添加按钮的GridView,item的删除事件
    先上图片效果;gridView无数据时显示添加按钮,有数据时,第一格显示添加按钮,后面显示数据:布局文件:addr_manage.xml<?xmlve ... [详细]
  • 本文介绍了一种解决PyQt界面在高分辨率下字体显示不完全的方法。通过设置High_DPI属性或应用自适应字体,可以解决在更高分辨率电脑上字体被控件遮挡的问题。同时,还提供了判断Qt版本和设置字体大小的代码示例。 ... [详细]
  • 本文介绍了一个Magento模块,其主要功能是实现前台用户利用表单给管理员发送邮件。通过阅读该模块的代码,可以了解到一些有关Magento的细节,例如如何获取系统标签id、如何使用Magento默认的提示信息以及如何使用smtp服务等。文章还提到了安装SMTP Pro插件的方法,并给出了前台页面的代码示例。 ... [详细]
  • loader资源模块加载器webpack资源模块加载webpack内部(内部loader)默认只会处理javascript文件,也就是说它会把打包过程中所有遇到的 ... [详细]
  • 今天就跟大家聊聊有关怎么在Android应用中实现一个换肤功能,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根 ... [详细]
  • SmartRefreshLayout自定义头部刷新和底部加载
    1.添加依赖implementation‘com.scwang.smartrefresh:SmartRefreshLayout:1.0.3’implementation‘com.s ... [详细]
author-avatar
mobiledu2502872453
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有