Skip to content

Commit 0416032

Browse files
committed
core/reloader: trigger postReload with a signal
A signal is now used over the previous tree-searching method as some QML components such as Repeater fail to reparent created children to themselves, which breaks the tree.
1 parent 1644ed5 commit 0416032

File tree

6 files changed

+15
-16
lines changed

6 files changed

+15
-16
lines changed

src/core/generation.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,9 @@ void EngineGeneration::postReload() {
161161
if (this->engine == nullptr || this->root == nullptr) return;
162162

163163
QsEnginePlugin::runOnReload();
164-
PostReloadHook::postReloadTree(this->root);
165-
this->singletonRegistry.onPostReload();
164+
165+
emit this->firePostReload();
166+
QObject::disconnect(this, &EngineGeneration::firePostReload, nullptr, nullptr);
166167
}
167168

168169
void EngineGeneration::setWatchingFiles(bool watching) {

src/core/generation.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class EngineGeneration: public QObject {
7575
signals:
7676
void filesChanged();
7777
void reloadFinished();
78+
void firePostReload();
7879

7980
public slots:
8081
void quit();

src/core/reload.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,18 @@ QObject* Reloadable::getChildByReloadId(QObject* parent, const QString& reloadId
129129
void PostReloadHook::componentComplete() {
130130
auto* engineGeneration = EngineGeneration::findObjectGeneration(this);
131131
if (!engineGeneration || engineGeneration->reloadComplete) this->postReload();
132+
else {
133+
// disconnected by EngineGeneration::postReload
134+
QObject::connect(
135+
engineGeneration,
136+
&EngineGeneration::firePostReload,
137+
this,
138+
&PostReloadHook::postReload
139+
);
140+
}
132141
}
133142

134143
void PostReloadHook::postReload() {
135144
this->isPostReload = true;
136145
this->onPostReload();
137146
}
138-
139-
void PostReloadHook::postReloadTree(QObject* root) {
140-
for (auto* child: root->children()) PostReloadHook::postReloadTree(child);
141-
if (auto* self = dynamic_cast<PostReloadHook*>(root)) self->postReload();
142-
}

src/core/reload.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,10 @@ class PostReloadHook
131131
void classBegin() override {}
132132
void componentComplete() override;
133133

134-
void postReload();
135134
virtual void onPostReload() = 0;
136135

137-
static void postReloadTree(QObject* root);
136+
public slots:
137+
void postReload();
138138

139139
protected:
140140
bool isPostReload = false;

src/core/singleton.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,3 @@ void SingletonRegistry::onReload(SingletonRegistry* old) {
5151
singleton->reload(old == nullptr ? nullptr : old->registry.value(url));
5252
}
5353
}
54-
55-
void SingletonRegistry::onPostReload() {
56-
for (auto* singleton: this->registry.values()) {
57-
PostReloadHook::postReloadTree(singleton);
58-
}
59-
}

src/core/singleton.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ class SingletonRegistry {
2626

2727
void registerSingleton(const QUrl& url, Singleton* singleton);
2828
void onReload(SingletonRegistry* old);
29-
void onPostReload();
3029

3130
private:
3231
QHash<QUrl, Singleton*> registry;

0 commit comments

Comments
 (0)