Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
src_gui_kernel_qguiapplication.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#include <QApplication>
4#include <QMessageBox>
5#include <QSessionManager>
6#include <QWidget>
7
9struct MyMainWidget : public QWidget
10{
13 bool saveDocument() { return true; };
16};
18void do_something(QString command) { Q_UNUSED(command); };
20
22int main(int argc, char *argv[])
23{
25 QApplication app(argc, argv);
26 // ...
27 return app.exec();
28}
30
31
35{
38}
39
41{
42 if (manager.allowsInteraction()) {
45 tr("My Application"),
46 tr("Save changes to document?"),
48
49 switch (ret) {
51 manager.release();
52 if (!saveDocument())
53 manager.cancel();
54 break;
56 break;
58 default:
59 manager.cancel();
60 }
61 } else {
62 // we did not get permission to interact, then
63 // do something reasonable instead
64 }
65}
67
68
69/* wrap snippet 2
70
72appname -session id
74
75*/ // wrap snippet 2
76
77
78void wrapper0() {
79
80
83for (const QString &command : commands)
84 do_something(command);
86
87} // wrapper0
88
89
90void wrapper1() {
93for (const QString &command : mySession.discardCommand())
94 do_something(command);
96
97
98} // wrapper1
99} // src_gui_kernel_qguiapplication
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...
void commitDataRequest(QSessionManager &sessionManager)
static void setDesktopSettingsAware(bool on)
Sets whether Qt should use the system's standard colors, fonts, etc., to on.
static StandardButton warning(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:311
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2823
The QSessionManager class provides access to the session manager.
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
int main()
[0]
MyMainWidget mySession(nullptr)
#define qApp
return ret
GLsizei const GLubyte * commands
#define tr(X)
#define Q_UNUSED(x)
do_something()
QApplication app(argc, argv)
[0]
QNetworkAccessManager manager
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent