Hotloader.pri
Hot Reload QML Files
Install / Use
/learn @benlau/Hotloader.priREADME
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);
});
Related Skills
node-connect
347.2kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
108.0kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
347.2kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
347.2kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
