QVariant HostModel::data(const QModelIndex &index, int role) const { if (index.row() < 0 || index.row() >= m_hosts.count()) return QVariant(); Host* host = m_hosts.at(index.row()); switch (index.column()) { case 0: { switch (role) { case NameRole: return host->name(); case AddressRole: return host->address(); } break; } case 1: if (role == Qt::DisplayRole) return host->name(); break; case 2: if (role == Qt::DisplayRole) return host->productVersion(); break; case 3: if (role == Qt::DisplayRole) return host->systemName(); break; case 4: if (role == Qt::DisplayRole) return QString("%1:%2").arg(host->address()).arg(host->port()); break; } return QVariant(); }