Skip to content

Commit b50583e

Browse files
committed
Add Felgo Hot Reload
1 parent bc31fb6 commit b50583e

File tree

5 files changed

+88
-0
lines changed

5 files changed

+88
-0
lines changed

CMakeLists.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ install(TARGETS FelgoHotReloadDemo
5959
BUNDLE DESTINATION .
6060
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
6161

62+
63+
set(FelgoHotReload_DIR "${FELGO_HOT_RELOAD_PATH}/lib/cmake/FelgoHotReload" CACHE PATH "FelgoHotReload directory" FORCE)
64+
find_package(FelgoHotReload CONFIG REQUIRED)
65+
66+
felgohotreload_configure_executable(${CURRENT_PROJECT_NAME})
67+
6268
# Add a static plugin
6369
add_subdirectory(qml_static_plugin)
6470
target_link_libraries(FelgoHotReloadDemo PRIVATE
@@ -76,6 +82,19 @@ qt_add_qml_module(FelgoHotReloadDemo
7682
NO_PLUGIN
7783
QML_FILES qml_module/QmlModuleText.qml)
7884

85+
# Generate configuration file
86+
cmake_path(
87+
RELATIVE_PATH CMAKE_CURRENT_BINARY_DIR
88+
BASE_DIRECTORY ${CMAKE_SOURCE_DIR}
89+
OUTPUT_VARIABLE FELGO_HOT_RELOAD_DEMO_BIN_DIR
90+
)
91+
92+
configure_file(
93+
${CMAKE_SOURCE_DIR}/hot_reload_config_template.json.in # Template file
94+
${CMAKE_SOURCE_DIR}/hot_reload_config.json # Configuration file
95+
@ONLY # Replace occurence of @VAR@
96+
)
97+
7998
if(QT_VERSION_MAJOR EQUAL 6)
8099
qt_import_qml_plugins(FelgoHotReloadDemo)
81100
qt_finalize_executable(FelgoHotReloadDemo)

FelgoHotReloadDemo.pro

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,5 @@ else: unix:!android: target.path = /opt/$${TARGET}/bin
2525
win32 {
2626
QMAKE_LFLAGS_WINDOWS += /DEBUG:NONE
2727
}
28+
29+
include("$${FELGO_HOT_RELOAD_PATH}/qmake/FelgoHotReload.pri")

hot_reload_config_qmake.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"main_qml_file": "qml/main.qml",
3+
4+
"qml_module_paths": [
5+
"qml",
6+
{
7+
"path": "qml_static_plugin",
8+
"target_path": "DemoStaticPlugin"
9+
},
10+
{
11+
"path": "qml_shared_plugin/qml",
12+
"target_path": "Demo/SharedPlugin"
13+
},
14+
{
15+
"path": "qml_module",
16+
"target_path": "demo/qml/module"
17+
}
18+
],
19+
20+
"qml_plugin_paths": [],
21+
22+
"use_local_plugins": true
23+
}

hot_reload_config_template.json.in

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"main_qml_file": "qml/main.qml",
3+
4+
"qml_module_paths": [
5+
"qml",
6+
{
7+
"path": "qml_static_plugin",
8+
"target_path": "DemoStaticPlugin"
9+
},
10+
{
11+
"path": "qml_shared_plugin",
12+
"target_path": "Demo/SharedPlugin"
13+
},
14+
{
15+
"path": "qml_module",
16+
"target_path": "demo/qml/module/qml_module"
17+
}
18+
],
19+
20+
"qml_plugin_paths": [
21+
{
22+
"path": "@FELGO_HOT_RELOAD_DEMO_BIN_DIR@/DemoStaticPlugin",
23+
"target_path": "DemoStaticPlugin"
24+
},
25+
{
26+
"path": "@FELGO_HOT_RELOAD_DEMO_BIN_DIR@/Demo/SharedPlugin",
27+
"target_path": "Demo/SharedPlugin"
28+
},
29+
{
30+
"path": "@FELGO_HOT_RELOAD_DEMO_BIN_DIR@/demo/qml/module",
31+
"target_path": "demo/qml/module"
32+
}
33+
],
34+
35+
"use_local_plugins": true
36+
}

main.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
#include <QQmlApplicationEngine>
33
#include <QStringLiteral>
44

5+
#ifdef USE_FELGO_HOT_RELOAD
6+
#include <FelgoHotReload>
7+
#endif
8+
59
int main(int argc, char *argv[])
610
{
711

@@ -12,7 +16,11 @@ int main(int argc, char *argv[])
1216
QGuiApplication app(argc, argv);
1317
QQmlApplicationEngine engine;
1418
engine.addImportPath(":/");
19+
#ifdef USE_FELGO_HOT_RELOAD
20+
static FelgoHotReload felgoHotReload(&engine);
21+
#else
1522
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
23+
#endif
1624
const auto result = app.exec();
1725
return result;
1826
}

0 commit comments

Comments
 (0)