QtBase  v6.3.1
src_gui_kernel_qapplication.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the documentation of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:BSD$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** BSD License Usage
18 ** Alternatively, you may use this file under the terms of the BSD license
19 ** as follows:
20 **
21 ** "Redistribution and use in source and binary forms, with or without
22 ** modification, are permitted provided that the following conditions are
23 ** met:
24 ** * Redistributions of source code must retain the above copyright
25 ** notice, this list of conditions and the following disclaimer.
26 ** * Redistributions in binary form must reproduce the above copyright
27 ** notice, this list of conditions and the following disclaimer in
28 ** the documentation and/or other materials provided with the
29 ** distribution.
30 ** * Neither the name of The Qt Company Ltd nor the names of its
31 ** contributors may be used to endorse or promote products derived
32 ** from this software without specific prior written permission.
33 **
34 **
35 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
36 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
37 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
38 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
39 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
42 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
43 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
44 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
45 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
46 **
47 ** $QT_END_LICENSE$
48 **
49 ****************************************************************************/
50 
52 QCoreApplication* createApplication(int &argc, char *argv[])
53 {
54  for (int i = 1; i < argc; ++i) {
55  if (!qstrcmp(argv[i], "-no-gui"))
56  return new QCoreApplication(argc, argv);
57  }
58  return new QApplication(argc, argv);
59 }
60 
61 int main(int argc, char* argv[])
62 {
64 
65  if (qobject_cast<QApplication *>(app.data())) {
66  // start GUI version...
67  } else {
68  // start non-GUI version...
69  }
70 
71  return app->exec();
72 }
74 
75 
79 
80 
81 // ### fixme: Qt 6: Remove [2]
83 int main(int argc, char *argv[])
84 {
85  QApplication::setColorSpec(QApplication::ManyColor);
86  QApplication app(argc, argv);
87  ...
88  return app.exec();
89 }
91 
92 
95 {
96  return QSize(80, 25);
97 }
99 
100 
103 {
104  const QWidgetList topLevelWidgets = QApplication::topLevelWidgets();
105  for (QWidget *widget : topLevelWidgets) {
106  if (widget->isHidden())
107  widget->show();
108  }
109 }
111 
112 
115 {
116  const QWidgetList allWidgets = QApplication::allWidgets();
117  for (QWidget *widget : allWidgets)
118  widget->update();
119 }
121 
122 
124 int main(int argc, char *argv[])
125 {
127  QApplication app(argc, argv);
128  ...
129  return app.exec();
130 }
132 
133 
135 if ((startPos - currentPos).manhattanLength() >=
137  startTheDrag();
139 
140 
142 void MyApplication::commitData(QSessionManager& manager)
143 {
144  if (manager.allowsInteraction()) {
146  mainWindow,
147  tr("My Application"),
148  tr("Save changes to document?"),
150 
151  switch (ret) {
152  case QMessageBox::Save:
153  manager.release();
154  if (!saveDocument())
155  manager.cancel();
156  break;
158  break;
159  case QMessageBox::Cancel:
160  default:
161  manager.cancel();
162  }
163  } else {
164  // we did not get permission to interact, then
165  // do something reasonable instead
166  }
167 }
169 
170 
172 appname -session id
174 
175 
178 for (const QString &command : commands)
179  do_something(command);
181 
182 
185 for (const QString &command : commands)
186  do_something(command);
188 
189 
192 if (widget)
193  widget = widget->window();
195 
196 
199 if (widget)
200  widget = widget->window();
small capitals from c petite p scientific i
[1]
Definition: afcover.h:80
QSize sizeHint() const override
[2]
The QApplication class manages the GUI application's control flow and main settings.
Definition: qapplication.h:68
static void setStyle(QStyle *)
static QWidget * widgetAt(const QPoint &p)
static QWidgetList topLevelWidgets()
static int exec()
int startDragDistance
the minimum distance required for a drag and drop operation to start.
Definition: qapplication.h:77
static QWidgetList allWidgets()
int qstrcmp(const char *str1, const char *str2)
Definition: qbytearray.cpp:215
The QCoreApplication class provides an event loop for Qt applications without UI.
static void setDesktopSettingsAware(bool on)
static StandardButton warning(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
The QScopedPointer class stores a pointer to a dynamically allocated object, and deletes it upon dest...
The QSessionManager class provides access to the session manager.
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:55
The QString class provides a Unicode character string.
Definition: qstring.h:388
The QStringList class provides a list of strings.
static QStyle * create(const QString &)
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:133
QWidget * window() const
Definition: qwidget.cpp:4319
bool isHidden() const
Definition: qwidget.h:910
void show()
Definition: qwidget.cpp:7825
void update()
Definition: qwidget.cpp:10977
MyMainWidget mySession(nullptr)
GLsizei const GLubyte * commands
[10]
GLint GLint GLint GLint GLint x
[0]
GLint y
#define tr(X)
do_something()
QApplication app(argc, argv)
[0]
QNetworkAccessManager manager
int main(int argc, char *argv[])
[1]
void updateAllWidgets()
[4]
QWidget * widget
[11]
void showAllHiddenTopLevelWidgets()
[3]
QCoreApplication * createApplication(int &argc, char *argv[])
[0]