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. [Solved] Ping-like Qt App - QTcpSocket?
Forum Updated to NodeBB v4.3 + New Features

[Solved] Ping-like Qt App - QTcpSocket?

Scheduled Pinned Locked Moved General and Desktop
12 Posts 8 Posters 18.7k 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.
  • P Offline
    P Offline
    phlucious
    wrote on last edited by
    #3

    Oh... duh. Thanks! With that correction, I get a new set of errors:

    @error: undefined reference to '_imp___ZN10QTcpSocketC1EP7QObject'
    error: undefined reference to _imp___ZN15QAbstractSocket13connectToHostERK7QStringt6QFlagsIN9QIODevice12OpenModeFlagEE' error: undefined reference to _imp___ZN15QAbstractSocket16waitForConnectedEi'
    error: undefined reference to _imp___ZNK15QAbstractSocket5errorEv' error: undefined reference to _imp___ZN10QTcpSocketD1Ev'
    error: undefined reference to `_imp___ZN10QTcpSocketD1Ev'
    error: collect2: ld returned 1 exit status@

    Any idea what's up?

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

      Add the network module to your .pro file
      @
      Qt += network
      @
      and be sure to re-run qmake.

      1 Reply Last reply
      0
      • R Offline
        R Offline
        Richard Neal
        wrote on last edited by
        #5

        QTcpSocket is part of the QtNetwork Module.

        To include the definitions of the module's classes, use the following directive:

        #include <QtNetwork>

        To link against the module, add this line to your qmake .pro file:

        QT += network

        For every positive is a negative and every negative is a positive.

        1 Reply Last reply
        0
        • O Offline
          O Offline
          octal
          wrote on last edited by
          #6

          Just for you to understand your mistake, when you're writing :

          @
          QTcpSocket messenger();
          @

          You're not declaring a local messenger variable and calling its constructor (QTcpSocket constructor), but you're in fact declaring a function that takes no parameter and returns a QTcpSocket.

          That's why you get a compiler error. That's a common mistake.

          1 Reply Last reply
          0
          • C Offline
            C Offline
            Cayan
            wrote on last edited by
            #7

            To make it properly work, you will need to host something like a server on the other machines to listen for the connection and simply reply. So you'll know when they are connected or not.
            To figure out the ping, you may measure the time between the send and receive packets.

            1 Reply Last reply
            0
            • P Offline
              P Offline
              phlucious
              wrote on last edited by
              #8

              Thanks for the feedback! Adding
              @QT += network@
              to the *.pro file did the trick.

              Cayan, I see what you're saying about needing a server, but that's another problem for another time. :) Thanks!

              1 Reply Last reply
              0
              • C Offline
                C Offline
                Cayan
                wrote on last edited by
                #9

                Sure, just tried to complement the full spam of replies with the same answer

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  AlekseyK
                  wrote on last edited by
                  #10

                  @messenger.connectToHost("192.168.0.254", 61000);
                  if(!messenger.waitForConnected(3000))@
                  this works only if we know an open port on a host. If not how can we ping then?

                  1 Reply Last reply
                  0
                  • E Offline
                    E Offline
                    Exec
                    wrote on last edited by
                    #11

                    so-called "C++ most vexing parse" by Scott Meyers :)

                    [quote author="octal" date="1314905127"]Just for you to understand your mistake, when you're writing :

                    @
                    QTcpSocket messenger();
                    @

                    You're not declaring a local messenger variable and calling its constructor (QTcpSocket constructor), but you're in fact declaring a function that takes no parameter and returns a QTcpSocket.

                    That's why you get a compiler error. That's a common mistake.[/quote]

                    Knowledge is power!

                    1 Reply Last reply
                    0
                    • raven-worxR Offline
                      raven-worxR Offline
                      raven-worx
                      Moderators
                      wrote on last edited by
                      #12

                      [quote author="AlekseyK" date="1388806544"]@messenger.connectToHost("192.168.0.254", 61000);
                      if(!messenger.waitForConnected(3000))@
                      this works only if we know an open port on a host. If not how can we ping then?[/quote]
                      this is exactly what is "ping" for...
                      Either way you implement the ping protocol by yourself, r call the systems ping-application and parse the response, etc. if you need it, or use a C++ ping lib, don't know if there is any available, just google it.

                      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                      If you have a question please use the forum so others can benefit from the solution in the future

                      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