Hello all, I'm using a QStateMachine to manage my application, and sometimes a signal with an argument triggers a transition and I want to get its argument inside of the transition slot, but I do not know how to. Below you can find an example of my problem:

Let's assume we have some kind of socket class that emits a signal every time it receives a new request:

Qt Code:
  1. class MySocket:public QTcpSocket
  2. {
  3. Q_OBJECT
  4.  
  5. public:
  6. ...
  7.  
  8. signals:
  9.  
  10. void newRequest(int request);
  11.  
  12. }
To copy to clipboard, switch view to plain text mode 

Then inside of my application I have a QStateMachine with this transition:

Qt Code:
  1. MySocket* mySocket = new MySocket();
  2.  
  3. QStateMachine machine;
  4.  
  5. QState *s1 = new QState();
  6. QState *s2 = new QState();
  7.  
  8. QSignalTransition* s1_s2_transition = s1->addTransition(mySocket, SIGNAL(newRequest(int)), s2);
  9. QObject::connect(s1, SIGNAL(triggered()), this, SLOT(s1_s2_transition_process());
  10.  
  11. machine.addState(s1);
  12. machine.addState(s2);
To copy to clipboard, switch view to plain text mode 

What I want to do is to get the int argument emitted with the newRequest signal inside the s1_s2_transition_process() slot:

Qt Code:
  1. void MyApplication::s1_s2_transition_process()
  2. {
  3. //here I want to get the int value emitted with the newRequest(int) signal
  4. }
To copy to clipboard, switch view to plain text mode 

What I did to solve this problem is to store the value in a property in MySocket class before emitting the signal and access it by using a public accesor. This would be MySocket class:

Qt Code:
  1. class MySocket:public QTcpSocket
  2. {
  3. Q_OBJECT
  4.  
  5. public:
  6. int lastRequest;
  7.  
  8. int getLastRequest() const {return lastRequest;};
  9.  
  10. signals:
  11.  
  12. void newRequest(int request);
  13. }
  14.  
  15. MySocket::extractRequestFromReceivedBytes()
  16. {
  17. ...
  18. // the request is extracted and stored in data
  19. ...
  20. lastRequest = data;
  21. emit newRequest(lastRequest);
  22. }
To copy to clipboard, switch view to plain text mode 

And the slot:

Qt Code:
  1. void MyApplication::s1_s2_transition_process()
  2. {
  3. int request = mySocket->getLastRequest();
  4. }
To copy to clipboard, switch view to plain text mode 

I don't like this solution because I think two signals could be emitted from MySocket class very close in time, the second one could overwrite the lastRequest property before the first slot was invoked, and then it would retrieve the second value twice.

Any idea of how to solve this issue or how to redesign my system?

Thanks in advance