PDA

View Full Version : QStateMachine, not getting entered()



jimiq
17th November 2009, 18:13
Hi,

I have set up a QStateMachine but I am not getting an entered() signal from any of the states and Creator editor is not even showing this in the class list as I type it in the connect function. I only get destroyed, polished and finished in the list. function code below.

What am I doing wrong? ....any suggestions.

Many thanks

Jim


connectionMachine = new QStateMachine(this);
disconnected_SM = new QState();
connecting_SM = new QState();
connected_SM = new QState();
statusCheck_SM = new QState();
commsReady_SM = new QState();

disconnected_SM->addTransition(this, SIGNAL(connectToHost_SM()), connecting_SM);
connecting_SM->addTransition(&commandSequencer, SIGNAL(connected()), connected_SM);
connected_SM->addTransition(this, SIGNAL(updatingStatus_SM()), statusCheck_SM);

connectionMachine->addState(disconnected_SM);
connectionMachine->addState(connecting_SM);
connectionMachine->addState(connected_SM);
connectionMachine->addState(statusCheck_SM);

connect(connecting_SM, SIGNAL(entered()), this, SLOT(debugConnecting()));
connect(connected_SM, SIGNAL(entered()), this, SLOT(updateStatus()));

connectionMachine->setInitialState(disconnected_SM);
connectionMachine->start();

wysota
17th November 2009, 20:35
Does connectToHost_SM() signal get emitted? Also check your console logs to see if there are any warnings from Qt.

jimiq
18th November 2009, 10:33
Hi wysota,

I put in a connect() for the connectToHost_SM to output under qDebug and that works so it seems as though it is emitted. The logs at runtime and compile time don't show any warnigns or errors.

Jim

wysota
18th November 2009, 10:50
connect() means it is connected, not that it is emitted.

jimiq
18th November 2009, 11:15
No, no....what I mean is that I put in


connect(this, SIGNAL(connectToHost_SM()), this, SLOT(debugConnectToHost_SM()));

in order to see if connectToHost_SM() is emitted and debugConnectToHost_SM() just outputs a qDebug message so I can see that at runtime connectToHost_SM() is emitted.

jim

wysota
18th November 2009, 12:22
Please provide a minimal compilable example reproducing the problem. The code you pasted looks correct so the problem is probably elsewhere. Try isolating it from the rest of your code.

jimiq
18th November 2009, 16:20
I haven't got round to getting a compiled version to post but I have noticed that the state machine does start. I have put a qDebug line after the .start() to check if the state machine is running but it comes back as not running!!!! any suggestions?

wysota
18th November 2009, 16:34
It's an asynchronous call. The machine will start next time Qt enters the event loop.

jimiq
18th November 2009, 17:30
I have no other events running at that time.
I checked if it was running later in the app and it still comes back with stopped

wysota
18th November 2009, 18:37
As already said, provide a minimal compilable example reproducing the problem. I can't help you without knowing what you did.

jimiq
19th November 2009, 11:17
I managed to find the problem. When you mentioned about it being an asynchronous call got me thinking. I found that I was calling the state machine in the constructor of my dialog and was trying to trigger it too early. I then added a slot/signal combination to wait for the started() signal from the state machine before trying to create the TCP socket and now all appears fine.

Thanks for your help.
Jim