How to get the IP address on your Ubuntu phone

Source: Internet
Author: User
Tags i18n

In this article, we show you how to get the IP address on your phone in the Ubuntu qml app.


We add some code to our main.cpp to get the IP address:


Main.cpp
#include <QGuiApplication> #include <QQmlApplicationEngine> #include <QQuickView> #include < Qnetworkinterface> #include <qqmlcontext>int main (int argc, char *argv[]) {    qguiapplication app (argc, argv );    qlist<qhostaddress> list = Qnetworkinterface::alladdresses ();    Qstringlist DataList;    for (int niter = 0; Niter < List.count (); niter++) {        qdebug () << list[niter].tostring ();        Datalist.append (list[niter].tostring ());    }    Qquickview view;    View.setsource (Qurl (qstringliteral ("qrc:///main.qml"));    View.setresizemode (Qquickview::sizerootobjecttoview);    Qqmlcontext *ctxt = View.rootcontext ();    Ctxt->setcontextproperty ("MyModel", Qvariant::fromvalue (DataList));    View.show ();    return app.exec ();}


Main.qml
Import QtQuick 2.0import ubuntu.components 1.1/*! \brief MainView with a Label and Button Elements.*/mainview {//ObjectName for functional testing purposes (autopilot- QT5) ObjectName: "MainView"//note!     ApplicationName needs to match the "name" field of the click Manifest ApplicationName: "Ipaddress.liu-xiao-guo"/* The enables the application to change orientation when the device is rotated.    The default is False.    *///automaticorientation:true//Removes the old toolbar and enables new features of the new header.        Usedeprecatedtoolbar:false width:units.gu (height:units.gu) page {title:i18n.tr ("IPAddress") Column {spacing:units.gu (2) Anchors {margins:units.gu (2) Fill : parent} label {Id:label objectName: "Label" Fontsi    Ze: "Large" text:i18n.tr ("IP addresses:")        } ListView {Width:parent.width height:parent.height-label.height            Model:mymodel Delegate:text {Text:modeldata} }        }    }}


To run our application:


This is the IP address that we display when using WiFi.
Our source code is: Git clone https://gitcafe.com/ubuntu/ipaddress.git


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

How to get the IP address on your Ubuntu phone

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.