Game Programming using Qt 5 Beginner's Guide
上QQ阅读APP看书,第一时间看更新

What just happened?

We created a new private slot in the MainWindow class and connected the clicked() signal of the Start new game button to the slot. When the user clicks on the button, Qt will call our slot, and the code we wrote inside it gets executed.

Ensure that you put any operations with the form elements after the  setupUi()   call. This function creates the elements, so 
ui->startNewGame  will simply be uninitialized before  setupUi() is called, and attempting to use it will result in undefined behavior.

qDebug() << ... is a convenient way to print debug information to the stderr (standard error output) of the application process. It's quite similar to the std::cerr << ... method available in the standard library, but it separates supplied values with spaces and appends a new line at the end.

Putting debug outputs everywhere quickly becomes inconvenient. Luckily, Qt Creator has powerful integration with C++ debuggers, so you can use  Debug  mode to check whether some particular line is executing, see the current values of the local variables at that location, and so on. For example, try setting a break point at the line containing  qDebug()  by clicking on the space to the left of the line number (a red circle indicating the break point should appear). Click on the  Start Debugging  button (a green triangle with a bug at the bottom-left corner of Qt Creator), wait for the application to launch, and press the  Start new game  button. When the application enters the break point location, it will pause, and Qt Creator's window will be brought to the front. The yellow arrow over the break point circle will indicate the current step of the execution. You can use the buttons below the code editor to continue execution, stop, or execute the process in steps. Learning to use the debugger becomes very important when developing large applications . We will talk more about using the debugger later (Online Chapter, https://www.packtpub.com/sites/default/files/downloads/MiscellaneousandAdvancedConcepts.pdf).