https://github.com/benlau/hotloader.pri
Hot Reload QML Files
https://github.com/benlau/hotloader.pri
Last synced: 8 months ago
JSON representation
Hot Reload QML Files
- Host: GitHub
- URL: https://github.com/benlau/hotloader.pri
- Owner: benlau
- License: apache-2.0
- Created: 2017-01-29T08:10:10.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-07-13T04:12:39.000Z (over 8 years ago)
- Last Synced: 2025-04-04T20:41:03.527Z (8 months ago)
- Language: C++
- Homepage:
- Size: 12.7 KB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-qt-qml - hotloader.pri - Hot Reload QML Files. (Development)
README
Hot Reload QML files
====================
Experimental Project. It is not usable yet, but welcome for suggestion on the proposed API.
Proposed API
```
HotLoader loader;
#ifdef QT_DEBUG
loader.setHotReloadEnabled(true); // By default, it is turned off.
#endif
loader.addResourceFile(SRCDIR + "qml.qrc");
// Add a resource file to be loaded. It will call `rcc` to compile and load to HotLoader.resourceMapRoot()
// If any file inside the qrc file was changed, it will trigger rebuild and restart the run()
// If hotReloadEnabled is not true, this function will do nothing.
return loader.run([&]() {
QQmlApplicationEngine engine;
// Add HotLoader.resourceMapRoot() and `qrc:/` to the import path
loader.init(&engine);
// load state in previous run
QByteArray state = loader.state();
// Initialize QQmlApplicationEngine (e.g addImageProvider, setContextProperty etc)
engine.load(loader.mappedUrl(":/main.qml"));
// If hotReloadEnabled is true, mappedUrl() insert `:/hot-loader-dynamic-resource` into the url.
// It will become ":/hot-loader-dynamic-resource/main.qml"
// If hotReloadEnabled is false, it will simply return the original value.
// Set state according to the snapshot data
/* Insert your code here*/
loader.exec(); // Execute event loop. It will be terminated if any monitored files changed
// Convert current state to snapshot data
state = /* Insert your code here*/
// Save state snapshot
loader.setState(state);
});
```