summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@digia.com>2013-11-27 17:38:12 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-11-28 16:14:43 +0100
commit1070aeb5521a95039cad3f4536e85e99526a4900 (patch)
tree2b31244780d129053fd30274bc3662be34f45eb4
parent605f63a1880400a5b540bab60ad68d3612bd71c1 (diff)
downloadqtquickcontrols-1070aeb5521a95039cad3f4536e85e99526a4900.tar.gz
Revise main() in examples
Replace the inconvenient QT_QUICK_CONTROLS_EXAMPLE_MAIN macro with a simpler macro that merely defines the actual application type. This way it's easier to do tweaks to main() when for example testing a different application font size. Moreover, browsing the example code becomes more convenient (especially online). Task-number: QTBUG-35083 Change-Id: I8203816a9112bf29b4661baa86bf4a196554db05 Reviewed-by: Jens Bache-Wiig <jens.bache-wiig@digia.com>
-rw-r--r--examples/quick/controls/basiclayouts/basiclayouts.pro1
-rw-r--r--examples/quick/controls/basiclayouts/main.qml1
-rw-r--r--examples/quick/controls/basiclayouts/src/main.cpp11
-rw-r--r--examples/quick/controls/gallery/gallery.pro1
-rw-r--r--examples/quick/controls/gallery/main.qml1
-rw-r--r--examples/quick/controls/gallery/src/main.cpp11
-rw-r--r--examples/quick/controls/shared/qtquickcontrolsapplication.h (renamed from examples/quick/controls/shared/qt_quick_controls_examplemain.h)29
-rw-r--r--examples/quick/controls/shared/shared.pri4
-rw-r--r--examples/quick/controls/splitview/main.qml1
-rw-r--r--examples/quick/controls/splitview/splitview.pro1
-rw-r--r--examples/quick/controls/splitview/src/main.cpp11
-rw-r--r--examples/quick/controls/tableview/main.qml2
-rw-r--r--examples/quick/controls/tableview/src/main.cpp11
-rw-r--r--examples/quick/controls/tableview/tableview.pro1
-rw-r--r--examples/quick/controls/texteditor/qml/main.qml1
-rw-r--r--examples/quick/controls/texteditor/src/main.cpp24
-rw-r--r--examples/quick/controls/texteditor/texteditor.pro1
-rw-r--r--examples/quick/controls/touch/main.qml1
-rw-r--r--examples/quick/controls/touch/src/main.cpp11
-rw-r--r--examples/quick/controls/touch/touch.pro1
20 files changed, 69 insertions, 56 deletions
diff --git a/examples/quick/controls/basiclayouts/basiclayouts.pro b/examples/quick/controls/basiclayouts/basiclayouts.pro
index 144ad0fe..a5586fe6 100644
--- a/examples/quick/controls/basiclayouts/basiclayouts.pro
+++ b/examples/quick/controls/basiclayouts/basiclayouts.pro
@@ -3,6 +3,7 @@ TARGET = basiclayouts
!android: !ios: !blackberry: qtHaveModule(widgets): QT += widgets
include(src/src.pri)
+include(../shared/shared.pri)
OTHER_FILES += \
main.qml
diff --git a/examples/quick/controls/basiclayouts/main.qml b/examples/quick/controls/basiclayouts/main.qml
index fe573aa6..18883d9a 100644
--- a/examples/quick/controls/basiclayouts/main.qml
+++ b/examples/quick/controls/basiclayouts/main.qml
@@ -47,6 +47,7 @@ import QtQuick.Controls 1.1
import QtQuick.Layouts 1.0
ApplicationWindow {
+ visible: true
title: "Basic layouts"
property int margin: 11
width: mainLayout.implicitWidth + 2 * margin
diff --git a/examples/quick/controls/basiclayouts/src/main.cpp b/examples/quick/controls/basiclayouts/src/main.cpp
index 57ba57e3..a757f485 100644
--- a/examples/quick/controls/basiclayouts/src/main.cpp
+++ b/examples/quick/controls/basiclayouts/src/main.cpp
@@ -38,5 +38,12 @@
**
****************************************************************************/
-#include "../../shared/qt_quick_controls_examplemain.h"
-QT_QUICK_CONTROLS_EXAMPLE_MAIN(qrc:/main.qml)
+#include "qtquickcontrolsapplication.h"
+#include <QtQml/QQmlApplicationEngine>
+
+int main(int argc, char *argv[])
+{
+ QtQuickControlsApplication app(argc, argv);
+ QQmlApplicationEngine engine(QUrl("qrc:/main.qml"));
+ return app.exec();
+}
diff --git a/examples/quick/controls/gallery/gallery.pro b/examples/quick/controls/gallery/gallery.pro
index 09358658..68ed0c16 100644
--- a/examples/quick/controls/gallery/gallery.pro
+++ b/examples/quick/controls/gallery/gallery.pro
@@ -3,6 +3,7 @@ TARGET = gallery
!android: !ios: !blackberry: qtHaveModule(widgets): QT += widgets
include(src/src.pri)
+include(../shared/shared.pri)
OTHER_FILES += \
main.qml \
diff --git a/examples/quick/controls/gallery/main.qml b/examples/quick/controls/gallery/main.qml
index 43b6776e..61e77ef8 100644
--- a/examples/quick/controls/gallery/main.qml
+++ b/examples/quick/controls/gallery/main.qml
@@ -49,6 +49,7 @@ import QtQuick.Dialogs 1.0
import "content"
ApplicationWindow {
+ visible: true
title: "Component Gallery"
width: 640
diff --git a/examples/quick/controls/gallery/src/main.cpp b/examples/quick/controls/gallery/src/main.cpp
index 57ba57e3..a757f485 100644
--- a/examples/quick/controls/gallery/src/main.cpp
+++ b/examples/quick/controls/gallery/src/main.cpp
@@ -38,5 +38,12 @@
**
****************************************************************************/
-#include "../../shared/qt_quick_controls_examplemain.h"
-QT_QUICK_CONTROLS_EXAMPLE_MAIN(qrc:/main.qml)
+#include "qtquickcontrolsapplication.h"
+#include <QtQml/QQmlApplicationEngine>
+
+int main(int argc, char *argv[])
+{
+ QtQuickControlsApplication app(argc, argv);
+ QQmlApplicationEngine engine(QUrl("qrc:/main.qml"));
+ return app.exec();
+}
diff --git a/examples/quick/controls/shared/qt_quick_controls_examplemain.h b/examples/quick/controls/shared/qtquickcontrolsapplication.h
index 7f73a6d1..171de6c6 100644
--- a/examples/quick/controls/shared/qt_quick_controls_examplemain.h
+++ b/examples/quick/controls/shared/qtquickcontrolsapplication.h
@@ -39,12 +39,8 @@
**
****************************************************************************/
-#ifndef QT_QUICK_CONTROLS_EXAMPLEMAIN_H
-#define QT_QUICK_CONTROLS_EXAMPLEMAIN_H
-
-#include <QtQml>
-#include <QtQuick/QQuickView>
-#include <QtCore/QString>
+#ifndef QTQUICKCONTROLSAPPLICATION_H
+#define QTQUICKCONTROLSAPPLICATION_H
#ifdef QT_WIDGETS_LIB
#include <QtWidgets/QApplication>
@@ -55,26 +51,11 @@
QT_BEGIN_NAMESPACE
#ifdef QT_WIDGETS_LIB
-#define Application QApplication
+#define QtQuickControlsApplication QApplication
#else
-#define Application QGuiApplication
+#define QtQuickControlsApplication QGuiApplication
#endif
-#define QT_QUICK_CONTROLS_EXAMPLE_MAIN(url) \
- int main(int argc, char *argv[]) \
- { \
- Application app(argc, argv); \
- QQmlApplicationEngine engine(QUrl(#url)); \
- QObject *topLevel = engine.rootObjects().value(0); \
- QQuickWindow *window = qobject_cast<QQuickWindow *>(topLevel); \
- if ( !window ) { \
- qWarning("Error: Your root item has to be a Window."); \
- return -1; \
- } \
- window->show(); \
- return app.exec(); \
- }
-
QT_END_NAMESPACE
-#endif // QT_QUICK_CONTROLS_EXAMPLEMAIN_H
+#endif // QTQUICKCONTROLSAPPLICATION_H
diff --git a/examples/quick/controls/shared/shared.pri b/examples/quick/controls/shared/shared.pri
new file mode 100644
index 00000000..8ca34737
--- /dev/null
+++ b/examples/quick/controls/shared/shared.pri
@@ -0,0 +1,4 @@
+INCLUDEPATH += $$PWD
+
+SOURCES += \
+ $$PWD/qtquickcontrolsapplication.h
diff --git a/examples/quick/controls/splitview/main.qml b/examples/quick/controls/splitview/main.qml
index 992607d6..395188ce 100644
--- a/examples/quick/controls/splitview/main.qml
+++ b/examples/quick/controls/splitview/main.qml
@@ -47,6 +47,7 @@ import QtQuick.Controls 1.1
import QtQuick.Layouts 1.0
ApplicationWindow {
+ visible: true
width: 600
height: 400
diff --git a/examples/quick/controls/splitview/splitview.pro b/examples/quick/controls/splitview/splitview.pro
index 066e578c..11c55f74 100644
--- a/examples/quick/controls/splitview/splitview.pro
+++ b/examples/quick/controls/splitview/splitview.pro
@@ -3,6 +3,7 @@ TARGET = splitview
!android: !ios: !blackberry: qtHaveModule(widgets): QT += widgets
include(src/src.pri)
+include(../shared/shared.pri)
OTHER_FILES += \
main.qml
diff --git a/examples/quick/controls/splitview/src/main.cpp b/examples/quick/controls/splitview/src/main.cpp
index 57ba57e3..a757f485 100644
--- a/examples/quick/controls/splitview/src/main.cpp
+++ b/examples/quick/controls/splitview/src/main.cpp
@@ -38,5 +38,12 @@
**
****************************************************************************/
-#include "../../shared/qt_quick_controls_examplemain.h"
-QT_QUICK_CONTROLS_EXAMPLE_MAIN(qrc:/main.qml)
+#include "qtquickcontrolsapplication.h"
+#include <QtQml/QQmlApplicationEngine>
+
+int main(int argc, char *argv[])
+{
+ QtQuickControlsApplication app(argc, argv);
+ QQmlApplicationEngine engine(QUrl("qrc:/main.qml"));
+ return app.exec();
+}
diff --git a/examples/quick/controls/tableview/main.qml b/examples/quick/controls/tableview/main.qml
index 37ab383e..e613e42e 100644
--- a/examples/quick/controls/tableview/main.qml
+++ b/examples/quick/controls/tableview/main.qml
@@ -48,7 +48,7 @@ import QtQuick.Controls 1.1
import QtQuick.XmlListModel 2.0
Window {
-
+ visible: true
width: 538 + frame.margins * 2
height: 360 + frame.margins * 2
diff --git a/examples/quick/controls/tableview/src/main.cpp b/examples/quick/controls/tableview/src/main.cpp
index 57ba57e3..a757f485 100644
--- a/examples/quick/controls/tableview/src/main.cpp
+++ b/examples/quick/controls/tableview/src/main.cpp
@@ -38,5 +38,12 @@
**
****************************************************************************/
-#include "../../shared/qt_quick_controls_examplemain.h"
-QT_QUICK_CONTROLS_EXAMPLE_MAIN(qrc:/main.qml)
+#include "qtquickcontrolsapplication.h"
+#include <QtQml/QQmlApplicationEngine>
+
+int main(int argc, char *argv[])
+{
+ QtQuickControlsApplication app(argc, argv);
+ QQmlApplicationEngine engine(QUrl("qrc:/main.qml"));
+ return app.exec();
+}
diff --git a/examples/quick/controls/tableview/tableview.pro b/examples/quick/controls/tableview/tableview.pro
index f3d7d7e6..7238d007 100644
--- a/examples/quick/controls/tableview/tableview.pro
+++ b/examples/quick/controls/tableview/tableview.pro
@@ -3,6 +3,7 @@ TARGET = tableview
!android: !ios: !blackberry: qtHaveModule(widgets): QT += widgets
include(src/src.pri)
+include(../shared/shared.pri)
OTHER_FILES += \
main.qml
diff --git a/examples/quick/controls/texteditor/qml/main.qml b/examples/quick/controls/texteditor/qml/main.qml
index 50cbed56..89120094 100644
--- a/examples/quick/controls/texteditor/qml/main.qml
+++ b/examples/quick/controls/texteditor/qml/main.qml
@@ -46,6 +46,7 @@ import QtQuick.Window 2.1
import org.qtproject.example 1.0
ApplicationWindow {
+ visible: true
width: 640
height: 480
minimumWidth: 400
diff --git a/examples/quick/controls/texteditor/src/main.cpp b/examples/quick/controls/texteditor/src/main.cpp
index a096f70d..ea7d22de 100644
--- a/examples/quick/controls/texteditor/src/main.cpp
+++ b/examples/quick/controls/texteditor/src/main.cpp
@@ -38,32 +38,14 @@
**
****************************************************************************/
-#ifdef QT_WIDGETS_LIB
-#include <QtWidgets/QApplication>
-#else
-#include <QtGui/QGuiApplication>
-#endif
-#include <QtQml>
-#include <QtQuick/QQuickView>
-#include <QtCore/QString>
-
+#include "qtquickcontrolsapplication.h"
#include "documenthandler.h"
+#include <QtQml/QQmlApplicationEngine>
int main(int argc, char *argv[])
{
-#ifdef QT_WIDGETS_LIB
- QApplication app(argc, argv);
-#else
- QGuiApplication app(argc, argv);
-#endif
+ QtQuickControlsApplication app(argc, argv);
qmlRegisterType<DocumentHandler>("org.qtproject.example", 1, 0, "DocumentHandler");
QQmlApplicationEngine engine(QUrl("qrc:/qml/main.qml"));
- QObject *topLevel = engine.rootObjects().value(0);
- QQuickWindow *window = qobject_cast<QQuickWindow *>(topLevel);
- if ( !window ) {
- qWarning("Error: Your root item has to be a Window.");
- return -1;
- }
- window->show();
return app.exec();
}
diff --git a/examples/quick/controls/texteditor/texteditor.pro b/examples/quick/controls/texteditor/texteditor.pro
index d9b6c8a3..06e669d9 100644
--- a/examples/quick/controls/texteditor/texteditor.pro
+++ b/examples/quick/controls/texteditor/texteditor.pro
@@ -3,6 +3,7 @@ TARGET = texteditor
!android: !ios: !blackberry: qtHaveModule(widgets): QT += widgets
include(src/src.pri)
+include(../shared/shared.pri)
OTHER_FILES += \
qml/main.qml \
diff --git a/examples/quick/controls/touch/main.qml b/examples/quick/controls/touch/main.qml
index a6de8910..ab5d534f 100644
--- a/examples/quick/controls/touch/main.qml
+++ b/examples/quick/controls/touch/main.qml
@@ -43,6 +43,7 @@ import QtQuick.Controls 1.1
import "content"
ApplicationWindow {
+ visible: true
width: 800
height: 1280
diff --git a/examples/quick/controls/touch/src/main.cpp b/examples/quick/controls/touch/src/main.cpp
index 57ba57e3..a757f485 100644
--- a/examples/quick/controls/touch/src/main.cpp
+++ b/examples/quick/controls/touch/src/main.cpp
@@ -38,5 +38,12 @@
**
****************************************************************************/
-#include "../../shared/qt_quick_controls_examplemain.h"
-QT_QUICK_CONTROLS_EXAMPLE_MAIN(qrc:/main.qml)
+#include "qtquickcontrolsapplication.h"
+#include <QtQml/QQmlApplicationEngine>
+
+int main(int argc, char *argv[])
+{
+ QtQuickControlsApplication app(argc, argv);
+ QQmlApplicationEngine engine(QUrl("qrc:/main.qml"));
+ return app.exec();
+}
diff --git a/examples/quick/controls/touch/touch.pro b/examples/quick/controls/touch/touch.pro
index 1e5d12f3..6afca140 100644
--- a/examples/quick/controls/touch/touch.pro
+++ b/examples/quick/controls/touch/touch.pro
@@ -3,6 +3,7 @@ TARGET = touch
!android: !ios: !blackberry: qtHaveModule(widgets): QT += widgets
include(src/src.pri)
+include(../shared/shared.pri)
OTHER_FILES += \
main.qml \