Qt窗口调度

来源:互联网 发布:淘宝网电脑网页版登陆 编辑:程序博客网 时间:2024/06/06 01:37
//main.cpp#include <QApplication>#include "tcp.h"#include "atm.h"int main(int argc, char *argv[]){    QApplication a(argc, argv);    //此处不可以用以及Atm类的构造函数中都不能用.exe,否则不能形成消息循环    Atm *w = new Atm;    return a.exec();}
//atm.h//主窗口#ifndef ATM_H#define ATM_H#include <QDialog>class Welcome;class Denglu;namespace Ui {class Atm;}class Atm : public QDialog{    Q_OBJECTpublic:    explicit Atm(QWidget *parent = 0);    ~Atm();     Welcome *welcome;    Denglu *denglu;private slots:       void on_Btn1_clicked();private:    Ui::Atm *ui;}
//atm.cpp#include "atm.h"#include "ui_atm.h"#include "welcome.h"Atm::Atm(QWidget *parent) :    QDialog(parent),    ui(new Ui::Atm){    ui->setupUi(this);    this->setFixedSize( this->width (),this->height ());//固定窗口大小    welcome = new Welcome;    welcome->show();    denglu = new Denglu;    //本地信号和槽    connect(welcome,SIGNAL(jump_to_denglu()),this,SLOT(respond_jump_to_denglu()));    connect(denglu,SIGNAL(jump_to_welcome()),this,SLOT(respond_jump_to_welcome()));}//————————————————————————按键部分——————————————————————————void Atm::on_Btn1_clicked()//按键1:开户{//注意,此处是可以学习的地方,开户完还得返回主界面,因此先将主界面隐藏,开户完成后,再将主界面显示出来。    this->hide();    kaihu->exec();    this->show();}
//welcome.h//欢迎界面#ifndef WELCOME_H#define WELCOME_H#include <QDialog>#include <QString>namespace Ui {class Welcome;}class Welcome : public QDialog{    Q_OBJECTpublic:    explicit Welcome(QWidget *parent = 0);    ~Welcome();signals:    void jump_to_denglu();    void jump_to_zhuce();    void ask_for_close();private slots:    void on_Btn1_clicked();    void on_Btn2_clicked();    void on_Btn_3_clicked();private:    Ui::Welcome *ui;};#endif // WELCOME_H
//welcome.cpp#include "welcome.h"#include "ui_welcome.h"#include <QProgressDialog>Welcome::Welcome(QWidget *parent) :    QDialog(parent),    ui(new Ui::Welcome){    ui->setupUi(this);    this->setFixedSize( this->width (),this->height ());//固定窗口大小    this->setWindowFlags(Qt::FramelessWindowHint);//去掉标题栏}Welcome::~Welcome(){    delete ui;}void Welcome::on_Btn1_clicked()//注册{    emit jump_to_denglu();    this->hide();}void Welcome::on_Btn2_clicked(){    emit jump_to_zhuce();    this->hide();}void Welcome::on_Btn_3_clicked(){    emit ask_for_close();    this->hide();}
0 0