QT for multi-window switching

Source: Internet
Author: User


This article turned from: http://www.2cto.com/kf/201203/124441.html. QT Multi-window switching program layout in 1.ui files

2. Main program main.cpp

#include <QtGui/QApplication>  
#include "mainwindow.h"  
 
int main (int argc, char *argv[]) 
{ 
    Qapplication A (argc, argv); 
    MainWindow W; 
    W.show (); 
     
    return a.exec (); 
} 

Main interface Program:
mainwindow.h
ifndef mainwindow_h 
#define MAINWINDOW_H  
 
#include <QMainWindow>  
#include "Dialog1.h"  
# Include "Dialog2.h"  
 
namespace Ui { 
class MainWindow; 
} 
 
Class Mainwindow:public Qmainwindow 
{ 
    q_object public 
     
: 
    explicit MainWindow (Qwidget *parent = 0); C12/>~mainwindow (); 
     
Private slots: 
    void on_pushbutton_clicked (); 
 
    void on_pushbutton_2_clicked (); 
 
 
    void on_pushbutton_3_clicked (); 
 
Private: 
    Ui::mainwindow *ui; 
    Dialog1 Dialog1; 
    Dialog2 dialog2; 
}; 
 
#endif//Mainwindow_h 


Mainwindow.cpp

"> #include" mainwindow.h " 
#include" ui_mainwindow.h "  
 
 
Mainwindow::mainwindow (Qwidget *parent): 
    Qmainwindow (parent), 
    UI (new Ui::mainwindow) 
{ 
    ui->setupui (this); 
 
} 
 
Mainwindow::~mainwindow () 
{ 
    delete ui; 
} 
 
void mainwindow::on_pushbutton_clicked () 
{ 
    this->hide (); 
    Dialog1.show (); 
    Dialog1.exec (); 
    This->show (); 
 
} 
 
void mainwindow::on_pushbutton_2_clicked () 
{ 
    this->close (); 
} 
 
 
 
void mainwindow::on_pushbutton_3_clicked () 
{ 
    this->close (); 
    Dialog2.show (); 
    Dialog2.exec (); 
    This->show (); 
} 

Dialog1.cpp
#include "dialog1.h"  
#include "Ui_dialog1.h"  
 
Dialog1::D ialog1 (Qwidget *parent): 
    qdialog (parent), 
    UI (New UI::D ialog1) 
{ 
    ui->setupui (this); 
} 
 
Dialog1::~dialog1 () 
{ 
    delete ui; 
} 
 
void dialog1::on_pushbutton_clicked () 
{ 
 
    this->close (); 
} 

Dialog2.cpp is similar to Dialog1

Key points:

This->close ();
Dialog2.show ();
Dialog2.exec ();
This->show ();
determine if the main interface is echoing by waiting for the dialog.exec () message. Operation Result:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.