Use of <QtConcurrentRun> - Asynchronous Run on a Network class
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
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:
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!
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&)'
What u need is to build a Soap Server / Client solution no ?
I never heard about soap before! Any way to fix it easily ?
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.
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 ?
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:
Hope this can clarify you.
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 !