summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorJens Bache-Wiig <jens.bache-wiig@digia.com>2013-05-31 16:07:00 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-06-07 09:39:58 +0200
commit3edcc79bcf9259c77732a8ad15bd8ed6919d4983 (patch)
tree5ab77c88f856d97aa4a6fed5e30a63e0efe7084d /examples
parenta258188d303f1d3767eda05cd1ce3a96f7541fd8 (diff)
downloadqtquickcontrols-3edcc79bcf9259c77732a8ad15bd8ed6919d4983.tar.gz
Simplify example code by using QmlApplicationEngine
Since QmlApplicationEngine does all the nasty bits including setting the incubation controller, we should use it in all of our examples. Task-number: QTBUG-31203 Change-Id: Ie4f2313b66ef1a460aa50559f5c0a6125d0c69f1 Reviewed-by: J-P Nurmi <jpnurmi@digia.com> Reviewed-by: Caroline Chao <caroline.chao@digia.com> Reviewed-by: Alan Alpert <aalpert@blackberry.com>
Diffstat (limited to 'examples')
-rw-r--r--examples/quick/controls/shared/qt_quick_controls_examplemain.h11
-rw-r--r--examples/quick/controls/text/src/main.cpp14
2 files changed, 4 insertions, 21 deletions
diff --git a/examples/quick/controls/shared/qt_quick_controls_examplemain.h b/examples/quick/controls/shared/qt_quick_controls_examplemain.h
index e3cae9a0..324d7110 100644
--- a/examples/quick/controls/shared/qt_quick_controls_examplemain.h
+++ b/examples/quick/controls/shared/qt_quick_controls_examplemain.h
@@ -64,20 +64,13 @@ QT_BEGIN_NAMESPACE
int main(int argc, char *argv[]) \
{ \
Application app(argc, argv); \
- QQmlEngine engine; \
- QQmlComponent component(&engine); \
- component.loadUrl(QUrl(#url)); \
- if ( !component.isReady() ) { \
- qWarning("%s", qPrintable(component.errorString())); \
- return -1; \
- } \
- QObject *topLevel = component.create(); \
+ 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; \
} \
- QObject::connect(&engine, SIGNAL(quit()), &app, SLOT(quit())); \
window->show(); \
return app.exec(); \
}
diff --git a/examples/quick/controls/text/src/main.cpp b/examples/quick/controls/text/src/main.cpp
index 0fc064dc..8d2b8dd0 100644
--- a/examples/quick/controls/text/src/main.cpp
+++ b/examples/quick/controls/text/src/main.cpp
@@ -49,24 +49,14 @@
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
- QQmlEngine engine;
-
qmlRegisterType<DocumentHandler>("org.qtproject.example", 1, 0, "DocumentHandler");
-
- QQmlComponent component(&engine);
- component.loadUrl(QUrl("qrc:/qml/main.qml"));
- if ( !component.isReady() ) {
- qWarning("%s", qPrintable(component.errorString()));
- return -1;
- }
- QObject *topLevel = component.create();
+ 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;
}
-
- QObject::connect(&engine, SIGNAL(quit()), &app, SLOT(quit()));
window->show();
return app.exec();
}