用QT信号和槽实现主界面有两个按钮,一个按钮打开新界面,另一个关闭新界面

来源:互联网 发布:淘宝网天天特价首页 编辑:程序博客网 时间:2024/05/16 18:35

很简单的 代码通俗易懂,没有分文件,方便贴去就直接编译,如果有不对的地方,请不吝赐教!!!

#include <QApplication>#include <QWidget>#include <QPushButton>#include <QHBoxLayout>int main(int argc, char** argv){    QApplication app(argc, argv);    QWidget widget;//创建空白窗口QWidget widget1;    QPushButton button1("show", &widget);    QPushButton button2("hide", &widget);    QHBoxLayout Hlayout(&widget);    Hlayout.addWidget(&button1);    Hlayout.addWidget(&button2);QObject::connect(&button1, SIGNAL(clicked()), &widget1, SLOT(show()));QObject::connect(&button2, SIGNAL(clicked()), &widget1, SLOT(hide()));widget.show();    return app.exec();}


1 0