expose completeInitialization() method
This commit is contained in:
parent
78689b3d40
commit
5562c65127
@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -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())
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user