Hello.

Which is the Qt behaviour respected to the program execution? I mean, when a signal is emitted and a slot executed in another class, is it running in parallel or is going to wait to finish the previous execution and then continue with the slot called?.

I ask this question because I have this case:

A for loop calls another function which emits a signal to send a mensage by a QSocket. My intension is to send the mesage and received an answer before continuing with the next step in the loop. Once the transmition and reception have finished continue with the for loop. But what is happenning is that the signal is emitted but the socket doesnt send it until the for loop which called have finished with all the steps.

It is difficult explain the problem, I hope you have understand me. I show you more or less the code to do it more easy.

Qt Code:
  1. .........
  2. for(i=0;i<n;i++) {
  3.  
  4. proof(i);
  5.  
  6. }
  7. ........
  8.  
  9. connect(this, SIGNAL(send()), SLOT(writeMsg()));
  10. connect(clienteSTTE->tcpSocket,SIGNAL(readyRead()),SLOT(leer()));
  11.  
  12. proof(int i){
  13.  
  14. emit send();
  15.  
  16. }
  17.  
  18. writeMsg{
  19.  
  20. QByteArray block;
  21. QDataStream out(&block, QIODevice::WriteOnly);
  22.  
  23.  
  24. QString string = QString(QLatin1String(this->mensajeEnviar.mensaje)) ;
  25. out.setVersion(QDataStream::Qt_4_0);
  26. out << (quint16)0;
  27. out << string;
  28. out.device()->seek(0);
  29. out << (quint16)(block.size() - sizeof(quint16));
  30.  
  31.  
  32. if(tcpSocket->isWritable()){
  33.  
  34. tcpSocket->write(block);
  35. }
  36. }
To copy to clipboard, switch view to plain text mode