QHostInfo



  • I'm new to QT and trying to get the host computer name and ip address. From what I can tell I should be using QHostInfo, but when I include this I get error's when compiling. I'm using QT Creator. Here's the details:

    Including in my .h file:

    @
    #include <QtNetwork/QHostInfo>
    @

    I then have a function that will do the following:

    @
    QHostInfo hostInfo;
    hostInfo = QHostInfo::fromName(QHostInfo::localHostName());
    QString hostName = QHostInfo::localHostName();
    qDebug() << hostName;
    @

    I then do a clean bulid, next run qMake, and then compile.

    When compiling, I'm getting the error:
    debug/mainwindow.o:C:\dev\qt\learning\helloworld-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Debug/../helloworld/mainwindow.cpp:58: undefined reference to `_imp___ZN9QHostInfoC1Ei'

    I get a lot of these error messages.

    I don't know what is causing this error, any help would be appriciated.

    thanks.

    [EDIT: code formatting, please wrap in @-tags, Volker]



  • In your project's .pro file you have to write "QT += network" without quotes.
    For future posts - wrap your code in @ symbols.



  • Thank you for the help. As I learn QT I would like to know where to find this kind of information in documentation. If you know, where would this be found.



  • Every class in Qt belongs to a "module":http://developer.qt.nokia.com/doc/qt-4.8/modules.html, for "QHostInfo":http://developer.qt.nokia.com/doc/qt-4.8/qhostinfo.html this is "QtNetwork":http://developer.qt.nokia.com/doc/qt-4.8/qtnetwork.html, whose documentation states:
    [quote]To link against the module, add this line to your qmake .pro file:
    <code>QT += network</code>[/quote]


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.