Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] UDP send data question
Qt 6.12 LTS is out! See what's new in the release blog

[SOLVED] UDP send data question

Scheduled Pinned Locked Moved General and Desktop
11 Posts 3 Posters 6.2k 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.
  • M Offline
    M Offline
    MrMNight
    wrote on last edited by
    #2

    "try read here":http://qt-project.org/doc/qt-5/qhostaddress.html#QHostAddress-6
    QHostAddress(bob_address);

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #3

      Thanks MrMNight,

      I did read through all that already... So you're telling me that all I have to do to set the host address is this:

      @bob_address = new QHostAddress("10.1.10.55");@

      then send it out like this:

      @udpSocket->writeDatagram(datagram.data(), datagram.size(), QHostAddress::bob_Address, 4595);@

      Right? I could swear I've done that already, but I'll try that and report back.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        MrMNight
        wrote on last edited by
        #4

        nope, i'm telling you do this:
        @
        //...
        QString bob_address = "10.1.10.55";
        udpSocket->writeDatagram(datagram.data(), datagram.size(), QHostAddress(bob_address), 4595);
        @

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #5

          Nope, that didn't work. I'm still getting the same error:

          @'bob_address' is not a member of 'QHostAddress'@

          This doesn't make any sense to me... All that data is in the constructor of my class, and is passed into the class functions. The first error shows on this line of the constructor:

          @udpSocket->bind(QHostAddress::bob_address, 4595);@

          I followed the "sender" and "receiver" examples posted in these threads but am still having trouble:

          "receiver.cpp":http://qt-project.org/doc/qt-5/qtnetwork-broadcastreceiver-receiver-cpp.html
          "receiver.h":http://qt-project.org/doc/qt-5/qtnetwork-broadcastreceiver-receiver-h.html
          "sender.cpp":http://qt-project.org/doc/qt-5/qtnetwork-broadcastsender-sender-cpp.html
          "sender.h":http://qt-project.org/doc/qt-5/qtnetwork-multicastsender-sender-h.html

          as well as several examples on stackoverflow.com, and "this page":http://www.bogotobogo.com/Qt/Qt5_QUdpSocket.php too.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            MrMNight
            wrote on last edited by
            #6

            You can simply wite QHostAddress::Broadcast because this is special case "described here:":http://qt-project.org/doc/qt-5/qhostaddress.html#SpecialAddress-enum , but you can't write QHostAddress::YourOwnName, you must construct object QHostAddress like this: QHostAddress("2.2.2.2") or like this: QHostAddress(someQStringThere), see documentation of "QHostAddress constructors:":http://qt-project.org/doc/qt-5/qhostaddress.html#QHostAddress

            1 Reply Last reply
            0
            • ? Offline
              ? Offline
              A Former User
              wrote on last edited by
              #7

              Ok, so my application HAS TO be specific in this case.... I can't just use Broadcast on 255.255.255.255 - it has to be a specific address - unless I'm misunderstanding what you're getting at...

              So I did this:
              @udpSocket->bind(QHostAddress("10.1.10.55"), 4595);@

              in my constructor and it compiles... but is it correct?

              I also tried this:

              @udpSocket->writeDatagram(datagram.data(), datagram.size(), QHostAddress("10.1.10.55"), 4595);@

              In my sending function - I'll assume it's correct since it compiled. I'll assume I don't need to bind it in the constructor as I did above if I just declare it in the "writeDatagram" function? Going to try to run the program in a moment. Few more tweaks first. Let you know if it works...

              Thanks for taking the time on this - it's a little abstract for me still...

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #8

                Hi,

                Your "not a member" error was because of this:

                @QHostAddress::bob_address@

                You are using colons rather than parenthesis

                @QHostAddress(bob_address)@

                Is the correct version

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • ? Offline
                  ? Offline
                  A Former User
                  wrote on last edited by
                  #9

                  oh... I misread the documentation then. I assume that case applies to using a QString address. I'm now able to transmit, thank you for your help! Now to make it receive :-)

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #10

                    Not really, calling something like "MyClass::something" means either you want to get an enum or a static variable member value

                    You're welcome !

                    Happy coding !

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    0
                    • ? Offline
                      ? Offline
                      A Former User
                      wrote on last edited by
                      #11

                      Thanks SGaist! This project I'm working on is my first ever windows application. I'm usually doing a little bit of C for embedded processors, and mostly simpler stuff. But this forum has been great so far, and has done the one thing I wanted: Help me understand this stuff!!

                      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
                      • Unsolved