main.qml 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import QtQuick 2.6
  2. import QtQuick.Window 2.2
  3. import gfa.plugins.qml.net 1.0
  4. Window {
  5. visible: true
  6. width: 640
  7. height: 480
  8. title: qsTr("Hello World")
  9. Text {
  10. id: idIpAddr
  11. x: 5
  12. y: 40
  13. color: "blue"
  14. font.pixelSize: 14
  15. text: idItf.interfaces[2].inet.stat.ipAddress.address
  16. }
  17. NetInterfaces {
  18. id: idItf
  19. // itfFilterName: "eth0"
  20. itfFilterAF: Interface.AF_Inet
  21. itfFilterMethod: Interface.IM_Static | Interface.IM_Manual
  22. onError:
  23. {
  24. console.error(msg);
  25. }
  26. onFilteredInterfacesChanged:
  27. {
  28. console.warn("Filtered Interfaces may have changed!");
  29. }
  30. }
  31. MouseArea {
  32. anchors.fill: parent
  33. onClicked:
  34. {
  35. if(idItf.filteredInterfaces.length > 0)
  36. {
  37. idItf.filteredInterfaces[0].inet.stat.ipAddress.address = "155.18.2.156";
  38. idItf.filteredInterfaces[0].inet.stat.ipAddress.b2 = 255;
  39. console.log(idItf.filteredInterfaces[0].inet.stat.ipAddress.address);
  40. }
  41. else
  42. {
  43. console.warn("No interface found!");
  44. }
  45. idItf.itfFilterMethod |= Interface.IM_Dhcp;
  46. idItf.itfFilterMethod &= ~Interface.IM_Manual;
  47. var itfn = idItf.newInterface("test1", Interface.AF_Inet6, Interface.IM_Dhcp);
  48. itfn.af = Interface.AF_Inet;
  49. itfn.inet.stat.ipAddress.address = "192.168.3.24";
  50. itfn.inet.stat.netMask.address = "255.255.254.0";
  51. itfn.inet.stat.netPrefix = 22;
  52. itfn.method = Interface.IM_Static;
  53. itfn.inet.stat.gateway.b0 = 192;
  54. itfn.inet.stat.gateway.b1 = 168;
  55. itfn.inet.stat.gateway.b2 = 0;
  56. itfn.inet.stat.gateway.b3 = 1;
  57. itfn.inet.stat.dnsServer[0].address = "8.8.8.8";
  58. itfn.inet.stat.dnsServer[1].address = "8.8.4.4";
  59. // idItf.removeInterface(itfn);
  60. idItf.saveAs("/home/wrk/share/gfanet/libgfanet/res/testitf");
  61. }
  62. }
  63. }