티스토리 뷰

Qt 강좌6 QMessageBox 메시지 박스 만들기 


New Project 


Qt Widgets Application 


Name: QMessageBoxExample





프로젝트 생성 완료 


ui에 푸쉬버튼을 만든다. 


푸쉬버튼 텍스트를 "Show Message"로 바꾼다. 


푸쉬버튼를 우클릭하고 Go to slot를 선택합니다. 


그리고 clicked()를 선택합니다. 


그럼 위와 같이 on_pushButton_clicked() 코드가 생성됩니다. 


다음과 같이 코딩합니다. 

 #include <QMessageBox>

 

그리고 다음과 같이 코딩해서 메시지 박스를 만들어요. 



#include "mainwindow.h"

#include "ui_mainwindow.h"

#include <QMessageBox>


MainWindow::MainWindow(QWidget *parent) :

    QMainWindow(parent),

    ui(new Ui::MainWindow)

{

    ui->setupUi(this);

}


MainWindow::~MainWindow()

{

    delete ui;

}


void MainWindow::on_pushButton_clicked()

{

    QMessageBox::about(this,"My Title","This is my custom message");

}



컴파일하면 위와 같이 창이 만들어집니다. 


Show Message를 클릭합니다. 



그럼 위와 같이 메시지 박스가 보이게 됩니다. 



aboutQt 메시지 박스



critical 메시지 박스 


information 메시지 박스



question메시지 박스



warning 메시지 박스 



다음과 같이 코딩합니다. 


#include "mainwindow.h"

#include "ui_mainwindow.h"

#include <QMessageBox>

#include <QDebug>


MainWindow::MainWindow(QWidget *parent) :

    QMainWindow(parent),

    ui(new Ui::MainWindow)

{

    ui->setupUi(this);

}


MainWindow::~MainWindow()

{

    delete ui;

}


void MainWindow::on_pushButton_clicked()

{

    QMessageBox::StandardButton reply = QMessageBox::question(this,

                          "My Title","This is my custom message",

                          QMessageBox::Yes | QMessageBox::No);


    if(reply == QMessageBox::Yes)

    {

        QApplication::quit();


    }

    else

    {

        qDebug() << "No is clicked";

    }

}


위와 같은 메시지창이 나옵니다.  Yes를 클릭하면 창은 종료됩니다. 



댓글
최근에 달린 댓글
글 보관함
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Total
Today
Yesterday
    뽀로로친구에디
    최근에 올라온 글