Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QUESTION]: Reloading QQuickWindow content without window recreation #6

Open
akontsevich opened this issue Dec 3, 2018 · 0 comments

Comments

@akontsevich
Copy link

https://stackoverflow.com/q/53601421/630169

For qml file with Item element as root of qml scene:

Item {
...
}

it is possible to preview qml file content with QQuickView without window recreation - see slightly modified and simplified qmlscene code:

QQmlEngine engine;
QPointer<QQmlComponent> component = new QQmlComponent(&engine);
QQuickWindow *window = nullptr;
auto qxView = new QQuickView(&engine, nullptr);

...

// Call this slot on file update (for example by QFileSystemWatcher signal)
updatePreview()
{
    // Recreate Qml Component
    engine.clearComponentCache();
    component = new QQmlComponent(&engine);
    component->loadUrl(url);
    QObject *topLevel = component->create();
    
    // Recreate Quick Window
    window = qobject_cast<QQuickWindow *>(topLevel);
    if (window) {
        engine.setIncubationController(window->incubationController());
    } else {
        QQuickItem *contentItem = qobject_cast<QQuickItem *>(topLevel);
        if (contentItem) {
            window = qobject_cast<QQuickWindow *>(qxView);
            qxView->setContent(url, component, contentItem);
        }
    }
}

For such qml file structure window become nullptr on Quick Window recreation and execution goes to else path of if statement. And there we use single QQuickView instance - qxView, just modifying its content without full reloading and recreation.

However if qml file contains ApplicationWindow as root item of the scene:

ApplicationWindow {
...
}

execution goes by the 1st variant of Quick Window recreation:

engine.setIncubationController(window->incubationController());

and new QQuickWindow instance created which takes much more time and force us to destroy and close previous one.

Is it possible analogous to QQuickView reload scene content for QQuickWindow without full window recreation? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant