Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Qt Scxml calculator-widgets example question
Forum Updated to NodeBB v4.3 + New Features

Qt Scxml calculator-widgets example question

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
3 Posts 2 Posters 436 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    d_h_mcinnes
    wrote on last edited by d_h_mcinnes
    #1

    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.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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;

      1 Reply Last reply
      2
      • D Offline
        D Offline
        d_h_mcinnes
        wrote on last edited by d_h_mcinnes
        #3

        Thank you very much. I hope I can return the favor one day.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved