Avec une listview

flags
Francois DELOBEL 4 weeks ago
parent f223c71103
commit 8d67fb7e82

@ -29,6 +29,14 @@ int main(int argc, char *argv[])
"Don't build NetworkInterface from QML"); "Don't build NetworkInterface from QML");
engine.rootContext()->setContextProperty("netint", &ni); engine.rootContext()->setContextProperty("netint", &ni);
QObjectList allInterfaces;
for ( QNetworkInterface iface : QNetworkInterface::allInterfaces() ) {
allInterfaces.push_back(new NetworkInterface{iface});
}
engine.rootContext()->setContextProperty("superliste", QVariant::fromValue(allInterfaces));
engine.load(url); engine.load(url);
return app.exec(); return app.exec();

@ -10,9 +10,23 @@ Window {
NetIf { NetIf {
id: netif
name: netint.name name: netint.name
address: netint.address address: netint.address
iface: netint iface: netint
} }
ListView {
anchors.top: netif.bottom
anchors.bottom: parent.bottom
width: parent.width
model: superliste
delegate: NetIf {
name: modelData.name
address: modelData.address
iface: modelData
}
}
} }

@ -5,7 +5,23 @@ NetworkInterface::NetworkInterface(int interfaceIndex, QObject *parent)
m_qni{QNetworkInterface::interfaceFromIndex(interfaceIndex)} m_qni{QNetworkInterface::interfaceFromIndex(interfaceIndex)}
{ {
setName(m_qni.name()); setName(m_qni.name());
setAddress(m_qni.addressEntries().first().ip().toString()); auto adresses = m_qni.addressEntries();
if ( adresses.size() == 0 )
setAddress("NO ADRESS");
else
setAddress(adresses.first().ip().toString());
}
NetworkInterface::NetworkInterface(QNetworkInterface iface, QObject *parent)
: QObject{parent},
m_qni{iface}
{
setName(m_qni.name());
auto adresses = m_qni.addressEntries();
if ( adresses.size() == 0 )
setAddress("NO ADRESS");
else
setAddress(adresses.first().ip().toString());
} }
QString NetworkInterface::name() const QString NetworkInterface::name() const

@ -12,6 +12,8 @@ class NetworkInterface : public QObject
Q_PROPERTY(QString address READ address WRITE setAddress NOTIFY addressChanged FINAL) Q_PROPERTY(QString address READ address WRITE setAddress NOTIFY addressChanged FINAL)
public: public:
explicit NetworkInterface(int interfaceIndex, QObject *parent = nullptr); explicit NetworkInterface(int interfaceIndex, QObject *parent = nullptr);
explicit NetworkInterface(QNetworkInterface iface, QObject *parent = nullptr);
QString name() const; QString name() const;
void setName(const QString &newName); void setName(const QString &newName);

Loading…
Cancel
Save