Skip to content

ovilab/QmlPreviewer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

75482a3 · Mar 15, 2017

History

23 Commits
Jan 28, 2017
Jan 4, 2017
Jan 4, 2017
Feb 27, 2017
Feb 28, 2017
Feb 28, 2017
Jan 28, 2017
Jan 28, 2017
Feb 28, 2017
Feb 28, 2017
Feb 27, 2017
Jan 28, 2017
Mar 15, 2017

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.