diff --git a/platform/qt/dmxwidget/widgetmodel.cpp b/platform/qt/dmxwidget/widgetmodel.cpp index 3fb6ff3..da8379f 100644 --- a/platform/qt/dmxwidget/widgetmodel.cpp +++ b/platform/qt/dmxwidget/widgetmodel.cpp @@ -8,6 +8,12 @@ WidgetModel::WidgetModel(QObject *parent) } +WidgetModel::~WidgetModel() { + for(auto &wdgt: widgets_) + disconnect(wdgt.get(), nullptr, this, nullptr); +} + + QVariant WidgetModel::headerData(int section, Qt::Orientation orientation, int role) const { if (role == Qt::DisplayRole && orientation == Qt::Horizontal) { @@ -127,5 +133,10 @@ void WidgetModel::rescanPorts() beginInsertRows(QModelIndex(), widgets_.size(), widgets_.size()+newWidgets.size()-1); widgets_.append(newWidgets); endInsertRows(); + for(auto &wdgt: newWidgets) + connect(wdgt.get(), &DmxWidget::connectedChanged, this, [this](){ + // refresh the whole view. Could be optimized by looking for this widget in the rows. + emit dataChanged(createIndex(0,0), createIndex(rowCount(),columnCount())); + }); } } diff --git a/platform/qt/dmxwidget/widgetmodel.h b/platform/qt/dmxwidget/widgetmodel.h index 0d0a8fb..d85fe28 100644 --- a/platform/qt/dmxwidget/widgetmodel.h +++ b/platform/qt/dmxwidget/widgetmodel.h @@ -9,6 +9,7 @@ class WidgetModel : public QAbstractItemModel public: explicit WidgetModel(QObject *parent = nullptr); + virtual ~WidgetModel(); // Header: QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;