Qt Scxml calculator-widgets example question
Solved
Qt Creator and other tools
-
Hi All
I have a question about the Qt Scxml calculator-widgets example. When I edit the 'main' function like this:
int main(int argc, char **argv)
{
QApplication app(argc, argv);CalculatorStateMachine machine; MainWindow mainWindow(&machine); machine.connectToState("begin", [](bool active) { cout << (active ? "entered" : "exited") << "begin state"; }); machine.connectToState("operand1", [](bool active) { cout << (active ? "entered" : "exited") << "operand1 state"; }); machine.connectToState("int1", [](bool active) { cout << (active ? "entered" : "exited") << "int1 state"; }); machine.connectToState("negated1", [](bool active) { cout << (active ? "entered" : "exited") << "negated1 state"; }); machine.start(); mainWindow.show(); return app.exec();
}
... and run from the command line, none of the couts appear on the terminal until I close the calculator terminal, then they all get dumped at once. Why is this? Are the couts actually getting executed when the events occur, but are buffered somehow? I expected the couts to be printed as the events occurred.
-
Hi
The cout is buffered, so you have to emit endlines to get it to flush or call flush.
cout << (active ? "entered" : "exited") << "operand1 state" << std::endl; -
Thank you very much. I hope I can return the favor one day.