I've made my application scriptable by creating a derived QThread class, where I add multiples QObject class in order to access their functions via the command line.
void commandLine::addObject(QObject *obj, QString name)
{
QScriptValue sv = m_scriptEngine.newQObject(obj);
m_scriptEngine.globalObject().setProperty(name, sv);
qObjectMap.insert(std::pair<QString, QObject *>(name, obj));
}
After the run() call, the class enter in an infinite loop, using m_scriptEngine to evaluate every command line entered.
In my (simplified) main I do :
simuCLI cli;
simuCore core;
cli.addObject(&core, "core");
simuUI ui;
connect(&ui, SIGNAL(start()), &core, SLOT(start()));
But when I call start() from my GUI and from my script, results are differents
My application architecture is like the following :
Core -> StateMachine -> Machine -> Communication
Start from UI works great.
Start from command line execute the code, but don't launch the QStateMachine and it emit signals, but never receive them.
Communication
sends commands to Machine
by emiting signals received in Machine
. It works if I've call core::start() from my UI
If I call core::start() using my command lines signal is emited but never received.
void WL::WL()
{
std::cout << "wl cst" << std::endl;
mLectMotStateMachine.setInitialState(sNoCard);
mLectMotStateMachine.start();
}
void WL::enterNoCard()
{
std::cout << "no card" << std::endl;
}
Ouput :
start() from UI :
wl cst
no card
start() from command line :
wl cst
As you can see, the state machine never enter in it first state, like it never launch.
So my questions are :
1 - In wich thread is executing start() if I call it from command line ?
2 - How can I debug signals ? (best answer I've found)
3 - Is there a way to see every Signals connection at a time 't' on execution
4 - How can I know in which thread I am on execution ?
5 - Have you any ideas of why my code isn't working only when I use the command line ?