QApplication docs: restore console mode -snippet
Change-Id: I1f8ce949ae660a209a2092a2863d5c25e2908004 Reviewed-by: Jerome Pasion <jerome.pasion@digia.com>
This commit is contained in:
parent
a31dd2e995
commit
e481ea595e
@ -39,23 +39,25 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
//! [0]
|
//! [0]
|
||||||
int main(int argc, char **argv)
|
QCoreApplication* createApplication(int &argc, char *argv[])
|
||||||
{
|
{
|
||||||
#ifdef Q_WS_X11
|
for (int i = 1; i < argc; ++i)
|
||||||
bool useGUI = getenv("DISPLAY") != 0;
|
if (!qstrcmp(argv[i], "-no-gui"))
|
||||||
#else
|
return new QCoreApplication(argc, argv);
|
||||||
bool useGUI = true;
|
return new QApplication(argc, argv);
|
||||||
#endif
|
}
|
||||||
QApplication app(argc, argv, useGUI);
|
|
||||||
|
|
||||||
if (useGUI) {
|
int main(int argc, char* argv[])
|
||||||
// start GUI version
|
{
|
||||||
...
|
QScopedPointer<QCoreApplication> app(createApplication(argc, argv));
|
||||||
|
|
||||||
|
if (qobject_cast<QApplication *>(app.data())) {
|
||||||
|
// start GUI version...
|
||||||
} else {
|
} else {
|
||||||
// start non-GUI version
|
// start non-GUI version...
|
||||||
...
|
|
||||||
}
|
}
|
||||||
return app.exec();
|
|
||||||
|
return app->exec();
|
||||||
}
|
}
|
||||||
//! [0]
|
//! [0]
|
||||||
|
|
||||||
|
@ -190,6 +190,15 @@ QApplicationPrivate::~QApplicationPrivate()
|
|||||||
any given time. For non-QWidget based Qt applications, use QGuiApplication instead,
|
any given time. For non-QWidget based Qt applications, use QGuiApplication instead,
|
||||||
as it does not depend on the \l QtWidgets library.
|
as it does not depend on the \l QtWidgets library.
|
||||||
|
|
||||||
|
Some GUI applications provide a special batch mode ie. provide command line
|
||||||
|
arguments for executing tasks without manual intervention. In such non-GUI
|
||||||
|
mode, it is often sufficient to instantiate a plain QCoreApplication to
|
||||||
|
avoid unnecessarily initializing resources needed for a graphical user
|
||||||
|
interface. The following example shows how to dynamically create an
|
||||||
|
appropriate type of application instance:
|
||||||
|
|
||||||
|
\snippet code/src_gui_kernel_qapplication.cpp 0
|
||||||
|
|
||||||
The QApplication object is accessible through the instance() function that
|
The QApplication object is accessible through the instance() function that
|
||||||
returns a pointer equivalent to the global qApp pointer.
|
returns a pointer equivalent to the global qApp pointer.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user