DevicesModel: Do not connect until the value is initialised
When the DevicesModel is open, we get a nullptr instance. I guess it's obvious that it's null because it hasn't been set yet. Move the connect to the setter.
This commit is contained in:
committed by
Aleix Pol Gonzalez
parent
7a6c234b40
commit
aea9984187
@@ -18,15 +18,6 @@ using namespace Quotient;
|
||||
DevicesModel::DevicesModel(QObject *parent)
|
||||
: QAbstractListModel(parent)
|
||||
{
|
||||
connect(m_connection, &Connection::sessionVerified, this, [this](const QString &, const QString &deviceId) {
|
||||
const auto it = std::find_if(m_devices.begin(), m_devices.end(), [deviceId](const Quotient::Device &device) {
|
||||
return device.deviceId == deviceId;
|
||||
});
|
||||
if (it != m_devices.end()) {
|
||||
const auto index = this->index(it - m_devices.begin());
|
||||
Q_EMIT dataChanged(index, index, {Type});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void DevicesModel::fetchDevices()
|
||||
@@ -162,6 +153,15 @@ void DevicesModel::setConnection(NeoChatConnection *connection)
|
||||
disconnect(m_connection, nullptr, this, nullptr);
|
||||
}
|
||||
m_connection = connection;
|
||||
connect(m_connection, &Connection::sessionVerified, this, [this](const QString &, const QString &deviceId) {
|
||||
const auto it = std::find_if(m_devices.begin(), m_devices.end(), [deviceId](const Quotient::Device &device) {
|
||||
return device.deviceId == deviceId;
|
||||
});
|
||||
if (it != m_devices.end()) {
|
||||
const auto index = this->index(it - m_devices.begin());
|
||||
Q_EMIT dataChanged(index, index, {Type});
|
||||
}
|
||||
});
|
||||
Q_EMIT connectionChanged();
|
||||
fetchDevices();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user