Important: Please read the Qt Code of Conduct -

[Solved]QProcess and DHCP

  • I have searched google on how to get the dhcp settings and the ip, gateway and mask from a debian machine.
    Maybe I have to read the ifconfig and get the values there but I really don't know.

    Anyone who has done this or have some ideas about how to handle this.

    My app runs with root privileges.

  • You might be interested in "this discussion":

  • Is there another way to make and get this settings from debian 6.0
    or do I need to get qt 4.7 to get apropriate libs I'm on qt 4.6.3 for the moment.

  • You can write your own wrapper that will invoke any Linux/Debian related commands to get the information you need. But this will not be very portable....

  • Moderators

    fluca: On the other hand calling a custom script to extract the information makes it easier to adapt the program to other linux environments: All you need to change is a script, not the code of the application itself.

    Considering that linux keeps changing quite fast (e.g. arch already deprecated the ifconfig tool) and the network setup varies a lot between distributions that might be a nice feature.

  • With "being less portable" I was meaning that you have to check the script for each deploy you are going to use. Having Qt portable across platforms, and having to rely on a platform specific script does not sound to me very portable. Nevertheless, I agree that changing a script is usually a quick and simple task, and can also be automated checking which platform the system is running an getting the right information in the right way (e.g., uname switch). The fact that Linux is changing so much and so fast makes it hard to deal with all possible deployments. Maybe /proc/net could come in help here, but again this is a linux specific feature and it is not going to work on other systems.

  • Moderators

    True, if there is a Qt way of getting the information that is definitely preferred.

  • Maybe I did this more complex then it realy needs to be.
    I simple used this code
    @void GlobalParams::getMyIP()
    QNetworkInterface *inter = new QNetworkInterface();
    QList<QNetworkInterface> list = inter->allInterfaces();

    for (int i = 0; i < list.size(); ++i) {
     if ("eth0"))
            QNetworkInterface iface = QNetworkInterface::interfaceFromName(;
            QList<QNetworkAddressEntry> entries = iface.addressEntries();
            if (!entries.isEmpty())
                QNetworkAddressEntry entry = entries.first();
                ip = entry.ip();
                netMask = entry.netmask();
                gateway = entry.broadcast();


    But as tou could see my gateway is filled up with the broadcastadress.
    And thats not what I want.

    Someone who knows how too get this:
    I have seen some code but it was not so obvious like this so I would like some simple example if there is one around.

Log in to reply