summaryrefslogtreecommitdiffstats
path: root/src/widgets/doc/snippets/code/src_gui_kernel_qapplication.cpp
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@digia.com>2012-12-10 14:09:55 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-12-11 18:34:19 +0100
commite481ea595e97456aec35e6a62d3ada62cddd0c2b (patch)
tree968e7c0e25c5eea2f11d9780981aee714db82546 /src/widgets/doc/snippets/code/src_gui_kernel_qapplication.cpp
parenta31dd2e995c91a5e3e429ad76afc90c0a2af3dcf (diff)
QApplication docs: restore console mode -snippet
Change-Id: I1f8ce949ae660a209a2092a2863d5c25e2908004 Reviewed-by: Jerome Pasion <jerome.pasion@digia.com>
Diffstat (limited to 'src/widgets/doc/snippets/code/src_gui_kernel_qapplication.cpp')
-rw-r--r--src/widgets/doc/snippets/code/src_gui_kernel_qapplication.cpp30
1 files changed, 16 insertions, 14 deletions
diff --git a/src/widgets/doc/snippets/code/src_gui_kernel_qapplication.cpp b/src/widgets/doc/snippets/code/src_gui_kernel_qapplication.cpp
index aa562078a6..b4b1eb5a00 100644
--- a/src/widgets/doc/snippets/code/src_gui_kernel_qapplication.cpp
+++ b/src/widgets/doc/snippets/code/src_gui_kernel_qapplication.cpp
@@ -39,23 +39,25 @@
****************************************************************************/
//! [0]
-int main(int argc, char **argv)
+QCoreApplication* createApplication(int &argc, char *argv[])
{
-#ifdef Q_WS_X11
- bool useGUI = getenv("DISPLAY") != 0;
-#else
- bool useGUI = true;
-#endif
- QApplication app(argc, argv, useGUI);
-
- if (useGUI) {
- // start GUI version
- ...
+ for (int i = 1; i < argc; ++i)
+ if (!qstrcmp(argv[i], "-no-gui"))
+ return new QCoreApplication(argc, argv);
+ return new QApplication(argc, argv);
+}
+
+int main(int argc, char* argv[])
+{
+ QScopedPointer<QCoreApplication> app(createApplication(argc, argv));
+
+ if (qobject_cast<QApplication *>(app.data())) {
+ // start GUI version...
} else {
- // start non-GUI version
- ...
+ // start non-GUI version...
}
- return app.exec();
+
+ return app->exec();
}
//! [0]