Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QHostInfo
Qt 6.11 is out! See what's new in the release blog

QHostInfo

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 6.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    IbisMojo
    wrote on last edited by
    #1

    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]

    1 Reply Last reply
    0
    • P Offline
      P Offline
      p-himik
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • I Offline
        I Offline
        IbisMojo
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • L Offline
          L Offline
          lgeyer
          wrote on last edited by
          #4

          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]

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved