Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Display device's IP address



  • Hello, I guess this is kind of a basic question but I was wondering how to display a device's IP address (kind of like doing ifconfig in a terminal and then just getting the IPv4 address ) on a label of a QtQuick application.

    I know it is possible to get the information from the C++ side but not sure how to link this to the qml side or if it is possible to do it from the qml side...

    #include <QtNetwork>
    const QHostAddress localhostAddress = QHostAddress(QHostAddress::LocalHost);
    

    I'm guessing I also need QT+= network in the .pro file?

    Thanks in advance for any help


  • Moderators

    A standard way is to expose a root context property to QML, containing your data. If you need a more sophisticated solution, create a class which will expose the address as QObject property.

    Example doc



  • @sierdzio thanks a lot for the pointer and example document, I will look into this