Skip to content

Commit

Permalink
Fixed stupid cast mistake in AbstractConfigObjectList. Addresses #194.
Browse files Browse the repository at this point in the history
  • Loading branch information
hmatuschek committed Jan 20, 2022
1 parent ab231d2 commit dd517d0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
8 changes: 6 additions & 2 deletions lib/configobject.cc
Original file line number Diff line number Diff line change
Expand Up @@ -985,9 +985,13 @@ AbstractConfigObjectList::onElementModified(ConfigItem *obj) {

void
AbstractConfigObjectList::onElementDeleted(QObject *obj) {
int idx = indexOf(qobject_cast<ConfigObject *>(obj));
if (0 <= idx)
// Use reinterpret cast here as the obj may already be destroyed and this all RTTI freed.
// We just use the pointer address to remove the element here.
int idx = indexOf(reinterpret_cast<ConfigObject *>(obj));
if (0 <= idx) {
_items.remove(idx);
emit elementRemoved(idx);
}
}


Expand Down
3 changes: 2 additions & 1 deletion lib/configobject.hh
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ protected:
virtual bool populate(YAML::Node &node, const Context &context);

signals:
/** Gets emitted once the config object is modified. */
/** Gets emitted once the config object is modified.
* The instance passed is the modified item, this event is passed up the config tree. */
void modified(ConfigItem *obj);
/** Gets emitted before clearing the item. */
void beginClear();
Expand Down
5 changes: 4 additions & 1 deletion lib/configreference.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ ConfigObjectReference::allow(const QMetaObject *elementType) {

void
ConfigObjectReference::onReferenceDeleted(QObject *obj) {
Q_UNUSED(obj)
// Check if destroyed obj is referenced one.
if (_object != reinterpret_cast<ConfigObject*>(obj))
return;
// If it is
_object = nullptr;
emit modified();
}
Expand Down

0 comments on commit dd517d0

Please sign in to comment.