Commit 1070aeb5 authored by J-P Nurmi's avatar J-P Nurmi Committed by The Qt Project
Browse files

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: default avatarJens Bache-Wiig <jens.bache-wiig@digia.com>
Showing with 69 additions and 56 deletions
......@@ -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
......
......@@ -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
......
......@@ -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();
}
......@@ -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 \
......
......@@ -49,6 +49,7 @@ import QtQuick.Dialogs 1.0
import "content"
ApplicationWindow {
visible: true
title: "Component Gallery"
width: 640
......
......@@ -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();
}
......@@ -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
INCLUDEPATH += $$PWD
SOURCES += \
$$PWD/qtquickcontrolsapplication.h
......@@ -47,6 +47,7 @@ import QtQuick.Controls 1.1
import QtQuick.Layouts 1.0
ApplicationWindow {
visible: true
width: 600
height: 400
......
......@@ -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
......
......@@ -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();
}
......@@ -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
......
......@@ -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();
}
......@@ -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
......
......@@ -46,6 +46,7 @@ import QtQuick.Window 2.1
import org.qtproject.example 1.0
ApplicationWindow {
visible: true
width: 640
height: 480
minimumWidth: 400
......
......@@ -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();
}
......@@ -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 \
......
......@@ -43,6 +43,7 @@ import QtQuick.Controls 1.1
import "content"
ApplicationWindow {
visible: true
width: 800
height: 1280
......
......@@ -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();
}
......@@ -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 \
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment