Skip to content

ovilab/QmlPreviewer

Repository files navigation

QmlPreviewer

Preview QML files even if they include C++ objects. QmlPreviewer works by watching the filesystem for changes to files listed in the .qrc resources and recompile and reload these immediately if they change.

Usage

Clone this repository into your project structure, for instance using git subrepo.

Include the .pri file in your .pro:

# ... your previous code
include(qmlpreviewer/qmlpreviewer.pri)

Include in main.cpp. Create, show and exec a QmlPreviewer object before your call app.exec() and after registering all your C++ types. Example:

#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QtQml>
// --- begin QmlPreviewer ----
#include <QmlPreviewer>
// --- end QmlPreviewer -----
#include "mytype.h"

int main(int argc, char *argv[])
{
    qmlRegisterType<MyType>("MyType", 1, 0, "MyType");

    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    QGuiApplication app(argc, argv);

    // --- begin QmlPreviewer ---
    QmlPreviewer previewer(app);
    if(previewer.show()) {
        return previewer.exec();
    }
    // --- end QmlPreviewer ---

    QQmlApplicationEngine engine;
    engine.load(QUrl(QLatin1String("qrc:/main.qml")));
    return app.exec();
}

Limitations

Images appear to be cached by the QML engine and are therefore not reloaded when they change on disk. Changes to images do however trigger a reload of the selected component.

Please feel free to report any other issues you encounter.

About

Preview QML files in your application

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published