diff --git a/platform/qt/qsacnuniverse.cpp b/platform/qt/qsacnuniverse.cpp index cea43ec..ec0a66e 100644 --- a/platform/qt/qsacnuniverse.cpp +++ b/platform/qt/qsacnuniverse.cpp @@ -238,27 +238,26 @@ void QSacnUniverse::setValue (const uint16_t addr, const uint16_t size, */ void QSacnUniverse::syncSources() { + // create a new list of sources QMap newSources; auto headers = universe_->sources(); for (const auto & metadata : headers) { - auto it = sources_.find(metadata); - if (it == sources_.end()) - { // not found + if (sources_.contains(metadata)) + // move the QSacnUniverse to the new list + newSources.insert(metadata, sources_.take(metadata)); + else + { // make a new QSacnUniverse to add to the new list auto universe = universe_->sourceUniverse(metadata); newSources.insert(metadata, new QSacnUniverse(this, universe)); } - else - { // found - auto universe = sources_.take(metadata); - newSources.insert(metadata, universe); - } } - // delete any remaining QSacnUniverse, ie. not moved to the new list + // delete any remaining sources, ie. not moved to the new list qDeleteAll(sources_); + // accept the new list sources_ = newSources; emit sourceListChanged(); }