Time for action – putting it all together

The visual part of the game is ready and what remains is to complete the logic of the main window and put all the pieces together. Add a public slot to the class and call it startNewGame. In the class constructor, connect the New Game action's triggered signal to this slot and connect the application's quit slot to the other action:

connect(ui->actionNewGame, SIGNAL(triggered()), this, SLOT(startNewGame()));
connect(ui->actionQuit, SIGNAL(triggered()), qApp, SLOT(quit()));

The qApp special macro represents a pointer to the application object instance, so the preceding code will call the quit() slot on the QApplication object created in main(), which in turn will eventually cause the application to end.

Get Game Programming Using Qt now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.