5#ifndef PONYPLAYER_HOTLOADER_H
6#define PONYPLAYER_HOTLOADER_H
8#include <QQmlApplicationEngine>
20 QQmlApplicationEngine *engine;
22 explicit HotLoader(QQmlApplicationEngine *e): engine(e) {
23 qDebug() <<
"Construct HotLoader.";
28 static std::string mainQML = std::filesystem::path(__FILE__).parent_path().string() +
"/view/main.qml";
29 auto *rootObject = engine->rootObjects().first();
30 auto* mainWindow = qobject_cast<QQuickWindow*>(rootObject);
31 Q_ASSERT( mainWindow !=
nullptr );
33 engine->clearComponentCache();
34 mainWindow->deleteLater();
35 engine->load(QUrl::fromLocalFile(QString::fromUtf8(mainQML)));
36 qWarning() <<
"Complete hot reloading.";
44 throw std::runtime_error(
"Crash Test!");
提供热重载支持
Definition: hotloader.hpp:17
HotLoader(QQmlApplicationEngine *e)
Definition: hotloader.hpp:22
Q_INVOKABLE void reload()
Definition: hotloader.hpp:26
Q_INVOKABLE void crash()
Definition: hotloader.hpp:42