From f223c7110344be10dedc7986fc7d8216641769d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Delobel?= Date: Tue, 25 Mar 2025 11:27:41 +0100 Subject: [PATCH] Variation pour expliquer QmlRegisterType --- 2024/tp4_reseau/NetIf.qml | 8 ++++++-- 2024/tp4_reseau/main.cpp | 3 +++ 2024/tp4_reseau/main.qml | 1 + 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/2024/tp4_reseau/NetIf.qml b/2024/tp4_reseau/NetIf.qml index 2a14451..2484bc8 100644 --- a/2024/tp4_reseau/NetIf.qml +++ b/2024/tp4_reseau/NetIf.qml @@ -1,11 +1,12 @@ import QtQuick 2.15 import QtQuick.Controls 2.15 +import trump.hatesScience 1.0 Row { property alias name: name.text property alias address: address.text - + property NetworkInterface iface spacing: 40 Text { @@ -21,7 +22,10 @@ Row { Button { text: "Shutdown" - onClicked: { netint.shutdown() } + onClicked: { + console.log("Sutting down") + parent.iface.shutdown() + } anchors.verticalCenter: parent.verticalCenter } } diff --git a/2024/tp4_reseau/main.cpp b/2024/tp4_reseau/main.cpp index 59cd1fe..f77ee72 100644 --- a/2024/tp4_reseau/main.cpp +++ b/2024/tp4_reseau/main.cpp @@ -24,6 +24,9 @@ int main(int argc, char *argv[]) Qt::QueuedConnection); NetworkInterface ni{3}; + qmlRegisterUncreatableType("trump.hatesScience",1,0, + "NetworkInterface", + "Don't build NetworkInterface from QML"); engine.rootContext()->setContextProperty("netint", &ni); engine.load(url); diff --git a/2024/tp4_reseau/main.qml b/2024/tp4_reseau/main.qml index 3fbd731..30ee661 100644 --- a/2024/tp4_reseau/main.qml +++ b/2024/tp4_reseau/main.qml @@ -12,6 +12,7 @@ Window { NetIf { name: netint.name address: netint.address + iface: netint } }