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. QUdpSocket HeartBeat behaviour [SOLVED]

QUdpSocket HeartBeat behaviour [SOLVED]

Scheduled Pinned Locked Moved General and Desktop
8 Posts 5 Posters 3.1k 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.
  • B Offline
    B Offline
    blackbelt
    wrote on last edited by
    #1

    Hello Guys, I need to send the status of my Qt application through and Upd socket every seconds. How can I achive this? Should I subclass QThread e using QThread::sleep or is there a best approch ? thanks

    1 Reply Last reply
    0
    • A Offline
      A Offline
      AcerExtensa
      wrote on last edited by
      #2

      Good idea to use QThread and sleep there in a while loop.
      Or you can use QTimer to trigger some slot every N time value you want...

      God is Real unless explicitly declared as Integer.

      1 Reply Last reply
      0
      • B Offline
        B Offline
        blackbelt
        wrote on last edited by
        #3

        I like the QTimer solution. Any possible drawbacks?

        thanks

        1 Reply Last reply
        0
        • I Offline
          I Offline
          issam
          wrote on last edited by
          #4

          You can use a QTimer inside a QThread loop like this :
          @
          void Thread::run()
          {
          QTimer timer;
          connect(&timer, SIGNAL(timeout()), this, SLOT(sendStatu()));
          timer.setInterval(5);
          timer.start();

          exec();
          timer.stop();
          }

          void Thread::sendStatu()
          {
          }
          @

          Important : when using signal and slots inside the thread run() function you must add exec(); This is because they need an event loop to be executed!

          http://www.iissam.com/

          1 Reply Last reply
          0
          • A Offline
            A Offline
            AcerExtensa
            wrote on last edited by
            #5

            Only one drawback: it works uses signal/slot connection, but it is also an advantage: No extra loops and triggered exactly when you need it... nothing more...

            God is Real unless explicitly declared as Integer.

            1 Reply Last reply
            0
            • B Offline
              B Offline
              blackbelt
              wrote on last edited by
              #6

              Ok but If a use the QTimer solutin could I avoid to subclass QThread?

              Thanks

              1 Reply Last reply
              0
              • T Offline
                T Offline
                twsimpson
                wrote on last edited by
                #7

                You can create a normal QObject that does the timing and writing to the socket, then use "QObject::moveToThread()":http://qt-project.org/doc/qt-4.8/qobject.html#moveToThread to have it run in that thread.
                A good example of how to do this is "this post":http://codethis.wordpress.com/2011/04/04/using-qthread-without-subclassing/

                1 Reply Last reply
                0
                • K Offline
                  K Offline
                  KA51O
                  wrote on last edited by
                  #8

                  Acctually you shouldn't subclass QThread if possible. Have a look at "this wiki entry":http://qt-project.org/wiki/QThreads_general_usage for a best practise description concerning QThreads.
                  Another option is QRunnable but in your case its not really feasable since thats more for a one time fire and forget sort of approach.

                  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