Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
src_gui_dialogs_qmessagebox.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
5int ret = QMessageBox::warning(this, tr("My Application"),
6 tr("The document has been modified.\n"
7 "Do you want to save your changes?"),
12
13
18
20
22 // connect
23} else if (msgBox.clickedButton() == abortButton) {
24 // abort
25}
27
28
33...
34messageBox.exec();
39
40
42#include <QApplication>
43#include <QMessageBox>
44
45int main(int argc, char *argv[])
46{
47 QT_REQUIRE_VERSION(argc, argv, "4.0.2")
48
49 QApplication app(argc, argv);
50 ...
51 return app.exec();
52}
54
57msgBox.setText("The document has been modified.");
58msgBox.exec();
60
63msgBox.setText("The document has been modified.");
64msgBox.setInformativeText("Do you want to save your changes?");
67int ret = msgBox.exec();
69
71switch (ret) {
73 // Save was clicked
74 break;
76 // Don't Save was clicked
77 break;
79 // Cancel was clicked
80 break;
81 default:
82 // should never be reached
83 break;
84}
The QAbstractButton class is the abstract base class of button widgets, providing functionality commo...
The QApplication class manages the GUI application's control flow and main settings.
static int exec()
Enters the main event loop and waits until exit() is called, then returns the value that was set to e...
virtual int exec()
Shows the dialog as a \l{QDialog::Modal Dialogs}{modal dialog}, blocking until the user closes it.
Definition qdialog.cpp:543
The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio...
Definition qmessagebox.h:22
void setStandardButtons(StandardButtons buttons)
static StandardButton warning(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
void addButton(QAbstractButton *button, ButtonRole role)
void setInformativeText(const QString &text)
QAbstractButton * clickedButton() const
void setText(const QString &text)
void setDefaultButton(QPushButton *button)
The QPushButton widget provides a command button.
Definition qpushbutton.h:20
int main()
[0]
#define QT_REQUIRE_VERSION(argc, argv, str)
#define tr(X)
QMessageBox msgBox
[0]
QMessageBox messageBox(this)
[2]
QAbstractButton * disconnectButton
QPushButton * connectButton
QPushButton * abortButton
QApplication app(argc, argv)
[0]