From 5562c651278109624adf7ecf74d19bced35bf305 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Tue, 5 Feb 2013 10:50:18 +0100 Subject: [PATCH] expose completeInitialization() method --- scriptengines/qml/declarative/qmlobject.cpp | 42 ++++++++++----------- scriptengines/qml/declarative/qmlobject.h | 10 ++++- 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/scriptengines/qml/declarative/qmlobject.cpp b/scriptengines/qml/declarative/qmlobject.cpp index 5ab10face..7d336168d 100644 --- a/scriptengines/qml/declarative/qmlobject.cpp +++ b/scriptengines/qml/declarative/qmlobject.cpp @@ -52,7 +52,6 @@ public: void errorPrint(); void execute(const QString &fileName); - void finishExecute(); void scheduleExecutionEnd(); void minimumWidthChanged(); void minimumHeightChanged(); @@ -111,31 +110,12 @@ void QmlObjectPrivate::execute(const QString &fileName) void QmlObjectPrivate::scheduleExecutionEnd() { if (component->isReady() || component->isError()) { - finishExecute(); + q->completeInitialization(); } else { - QObject::connect(component, SIGNAL(statusChanged(QQmlComponent::Status)), q, SLOT(finishExecute())); + QObject::connect(component, SIGNAL(statusChanged(QQmlComponent::Status)), q, SLOT(completeInitialization())); } } -void QmlObjectPrivate::finishExecute() -{ - if (component->isError()) { - errorPrint(); - } - - root = component->create(); - - if (!root) { - errorPrint(); - } - -#ifndef NDEBUG - kDebug() << "Execution of QML done!"; -#endif - - emit q->finished(); -} - QmlObject::QmlObject(QObject *parent) : QObject(parent), d(new QmlObjectPrivate(this)) @@ -191,7 +171,25 @@ QQmlComponent *QmlObject::mainComponent() const return d->component; } +void QmlObject::completeInitialization() +{ + if (d->component->status() != QQmlComponent::Ready || d->component->isError()) { + d->errorPrint(); + return; + } + d->root = d->component->create(); + + if (!d->root) { + d->errorPrint(); + } + +#ifndef NDEBUG + kDebug() << "Execution of QML done!"; +#endif + + emit finished(); +} diff --git a/scriptengines/qml/declarative/qmlobject.h b/scriptengines/qml/declarative/qmlobject.h index bfdcb9bb3..064a19294 100644 --- a/scriptengines/qml/declarative/qmlobject.h +++ b/scriptengines/qml/declarative/qmlobject.h @@ -77,6 +77,8 @@ public: * In this case will be possible to assign new objects in the main engine context * before the main component gets initialized. * So it will be possible to access it immediately from the QML code. + * The initialization will either be completed automatically asyncronously + * or explicitly by calling completeInitialization() * * @param delay if true the initialization of the QML file will be delayed * at the end of the event loop @@ -104,6 +106,13 @@ public: */ QQmlComponent *mainComponent() const; +public Q_SLOTS: + /** + * Finishes the process of initialization. + * If isInitializationDelayed() is false, calling this will have no effect. + */ + void completeInitialization(); + Q_SIGNALS: /** * Emitted when the parsing and execution of the QML file is terminated @@ -114,7 +123,6 @@ private: friend class QmlObjectPrivate; QmlObjectPrivate * const d; - Q_PRIVATE_SLOT(d, void finishExecute()) Q_PRIVATE_SLOT(d, void scheduleExecutionEnd()) };