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. Use of <QtConcurrentRun> - Asynchronous Run on a Network class
Forum Update on Monday, May 27th 2025

Use of <QtConcurrentRun> - Asynchronous Run on a Network class

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 2.6k Views
  • 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.
  • N Offline
    N Offline
    nazgai
    wrote on last edited by
    #1

    Hi all,

    I have been googling the web for a while and I cannot find the answer, even w/ Qt example.

    Here is the problem:

    • I want to communicate w/ an embedded system that gives me an answer each time I send a message

    • I got high level network class NetworkInterface that (de)connect to the network, send and receive message (those methods are virtual) from serial port (using qtsp) to the embedded module.

    So I send 1 unique message with this method
    @serialClass->sendMessage((QString) my_message);@

    and I got the answer with a connect
    @QObject::connect(serialClass, SIGNAL(readyRead()), this, SLOT(slotReceiveData()), Qt::DirectConnection);@

    That part work well!

    --

    Now if I want to send multiple questions, I stupidly use a while loop on my SQL table:

    @while(i<myTableMessage.size())
    {
    this->serialClass->sendMessage(myTableMessage[i++]);
    }@

    As we expected, the loop is too fast and as to be done to start readyRead() signal. So I send every message and only get the first answer!

    So what I want to acheive is :

    Send the message

    Stop the loop until I got the embedded answer

    display the answer

    continu the loop

    That is the reason why I need to use real time operating system by waiting the answer from my embedded module OR stop the while loop for several second and then reactive it!

    4 solutions:

    Using thread ? but my both functions send and received are on the same class and moreover are virtual

    Using semaphore or mutex ?

    Creating a kind of RTOS sytem by doing one unique action each sec (so the system got an action table to realized (beurk !))

    Using QtConcurrentRun ? but my both functions send and received still in the same class and moreover are virtual and does not accept that I declare

    @QFuture<void> future = QtConcurrent::run(sendMessage, message);@
    error: no matching function for call to 'run(<unresolved overloaded function type>, const QString&)'

    1 Reply Last reply
    0
    • B Offline
      B Offline
      bjanuario
      wrote on last edited by
      #2

      What u need is to build a Soap Server / Client solution no ?

      1 Reply Last reply
      0
      • N Offline
        N Offline
        nazgai
        wrote on last edited by
        #3

        I never heard about soap before! Any way to fix it easily ?

        1 Reply Last reply
        0
        • B Offline
          B Offline
          bjanuario
          wrote on last edited by
          #4

          SOAP, originally defined as Simple Object Access Protocol, is a protocol specification for exchanging structured information in the implementation of Web Services in computer networks.

          Qt have a strong partnership KDAB. You can have more info and examples on this link:
          "http://www.kdab.com/kdab-products/kd-soap/":http://www.kdab.com/kdab-products/kd-soap/

          1 Reply Last reply
          0
          • N Offline
            N Offline
            nazgai
            wrote on last edited by
            #5

            thx u bjanuario, by the way i m scared that it is not possible to use SOAP in my project, and I am sure it ll be possible to fix it using a different method ?

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

              You can use soap for that, but you can also use QCOP class.
              I never worked with that, but I have some friends did it.
              You can check this link:
              "http://harmattan-dev.nokia.com/docs/library/html/qt4/qcopchannel.html":http://harmattan-dev.nokia.com/docs/library/html/qt4/qcopchannel.html

              Hope this can clarify you.
              Kind Regard

              1 Reply Last reply
              0
              • N Offline
                N Offline
                nazgai
                wrote on last edited by
                #7

                Ok problem solve.

                In this king of trouble, the best way to fix it, is to code that way :

                • create a FIFO (w/ a vector<obejct> for example) between your GUI and network interface
                • send only one message from the fifo and pop this message.

                The reception is usually done with a connect like :
                @QObject::connect(ClassNetwork, SIGNAL(readyRead()), this, SLOT(my_slot());@

                In that case, it is easy to get the received message, and so, send the next FIFO message and pop it, etc.

                Finally use a thread for the time out :)

                Hope It will help u !

                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