(Q) Hello world!

Goal: I will learn to create a project in Qt Creator and go through the most essential properties of Qt Creator.

Instructions: Open a new Qt Project, the type of which is Plain C++ Application. (Most probably you have already done so during reading the instructions of the previous page. If not, do it now.) Qt Creator generates automatically a program that prints ”Hello world!”. We will explore the properties of Qt Creator by editing the generated code. During the task, answer to the following multiple choice questions.

* Compilation:

Test the functionality of the icons found in the left down corner in Qt Creator by modifying the program code and checking what happens when you press the icons. If your aim is to compile the written program code without executing it, which of the icons should you click?

* Execution:

What does the icon with green triangle do?

* Compilation errors:

Make an error in the program code, for example, remove a semicolon. Where does Qt Creator show the compilation error messages?

* Warnings:

Qt Creator shows a red circle before an error and a yellow triangle before a warning. What is the difference between errors and warnings?

* Program crash:

After the printing line, add the following line:

cout << "Division by zero: " << 1/0 << endl;

Division by zero produces a warning in compiling, and, of course, the program crahes when executing it. How can you see in Qt Creator that the program crashed?

* Running and closing debugger:

As you can concluded by the previous point, Qt Creator does not emphasize that the program crashed. It is easier to detect program crash, if you execute the program in debug mode. This can be done by clicking the green triangle with a bug. Debugger informs about the crash in a pop-up window and shows the line number, where the execution ended. When using debugger in Qt Creator, it is very important to note:

  1. Turn the debugger off by clicking the red square with a bug. Otherwise it continues execution and makes Qt Creator slow, especially if you have several debuggers executing.
  2. Move from debug mode back to edit mode by clicking the black menu on the left side.

If you forget to turn debugger off, but move to edit mode, how can you see from edit mode that the debugger is still on?

* Opening and closing files in a project:

Close file main.cpp (or main.cc), for example, by pressing X in the dark top bar of the edit window. How can you open the file just closed?