Qt Creator programming environment

This section briefly shows you the most essential phases to start working with Qt Creator programming environment. You will learn how to write and execute a simple program in the virtual desktop environment used on the course.

We assume that you have created a connection to the virtual desktop by following the guidance given in the previous section of the course material.

An alternative for working in the virtual desktop is to install Qt Creator on your own computer. Instructions can be found from the end part of this page. This is a considerable choice especially in remote mode, but note that in this case you should also install Git on your own computer. Tips for this can also be found from the end part of the page.

General issues on Qt Creator

The programs in Qt Creator are projects, and thus, they always include a file with .pro suffix. This file tells which source code files the program has. It is also the file that you will open, when your aim is to open an existing program in Qt. (As simplest, a program has only one source code file, main.cpp, besides the project file.)

When storing programs into version control and submitting them in Plussa, make sure that there is also the .pro file along.

How to use Qt Creator on virtual desktop

Follow the steps below when you are starting to write a new program with Qt Creator. Note that steps 1 and 3 are initial ones that are needed to be done only once before writing the first program.

  1. If you have earlier attended a course, where you have used Qt Creator, you would be better to remove the old settings. If there have been any maintainaining actions on C++ or Qt Creator after your last use of them, it is possible that Qt Creator do not work.

    So, if you are using Qt Creator from the remote desktop for the first time, this step does not concern you. You can move directly to step 2!

    During this step, Qt Creator must not be running. Otherwise the old settings will stay.

    Remove the old settings by removing all files in directory ~/.config/QtProject. Start file management by selecting Accessories -> Files:

    Screenshot on starting file management

    The opening window does not show system files starting with a dot. You can see them by adding a cross at ”Show hidden files”:

    Screenshot on making hidden files visible

    After that you can see the content of .config directory and you can remove all the files inside QtProject directory (which is inside the first-mentioned directory).

  2. Start Qt Creator tool from Applications > Programming > Qt Creator:

    Screenshot on starting Qt Creator

    when you can see the starting window of Qt Creator:

    Screenshot on starting window of Qt Creator
  3. From the top bar menu, choose Tools > Options..., where you can adjust the settings of Qt Creator. We may return to these setting later as the course advances, but already in this phase you can set the naming conventions of source code files.

    From {} C++, choose tab File Naming. Check that file suffix for Headers is hh and that for Sources is cpp (or cc):

    Screenshot on choosing file suffixes

    Choose OK from bottom right, and you will return to the starting window of Qt Cretor and everything should be ready for the first programming project.

  4. You can start a new programming project by clicking mouse at New Project in the starting window of Qt Creator. If you have already started to write a program and you are continuing it after a break, you can choose the desirable project under Open Project or Recent Projects directly with mouse. However, we assume here that you are starting a new project, and thus, you can choose New Project.

    After that you will see a couple of windows, where Qt Creator asks some details concerning the project before letting you to write program code.

  5. The first thing to decide is the type of the project. In the beginning part of the course, all the programs are basic C++ programs without graphical interfaces or other specific features. Therefore, choose first the type of the project as Non-Qt Project and the subtype as Plain C++ Application:

    Screenshot on choosing the type of the project

    After that select Choose... from the bottom right.

  6. Next selection concerns the directory, where Qt Creator will store all the files of the project.

    At Name: write a name describing you project as well as possible. For example weekly_exercise-01-task-03  and  project_work-01 are good names for the project.

    Next you need to decide the directory, where you store the project. For this first task you, you can make the decision by yourself. It can be a good idea to create a directory called prog2 for the course. This can be done in file system management of the virtual desktop or by clicking Browse in Project Location window and then, in the top right corner of the opening window, clicking Create Folder, after navigating in the desirable directory.

    After the selections described above, Qt shows the name selections done:

    Screenshot on successful end result

    Choose now Next> from bottom right.

  7. Everything in windows Build System and Kits should be ok, and it is sufficient to select Next> from bottom right.

  8. The last step before actual programming concerns Project Management window. Here you can choose a version control system for your project. Although we will use Git version control on the course, we will not yet do so for this first project. Therefore, at this time choose <None> at Add to version control. Finally, press Finish.

Running a program in Qt

By default Qt may have such a setting on that a program prints its output in Application Out. This setting can cause trouble if the program also asks user input. It is often more useful to run programs in separate window (with qtcreator_process_stub as its title):

Screenshot on running a program in separate window

You can set this option on as follows. From the top menu, choose Tools -> Options -> Build & Run. From General tab, at Default for "Running in terminal", choose Deduced From Project.

Screenshot on options to get separate execution window in use

In newer versions, Options cannot necessarily be found in the way described above. In such case, you can start by selecting Edit -> Prefences.

On installing Qt Creator to your own computer

It is possible to install Qt Creator to your computer, when you can write programs without internet connection. Installation process depends on the operating system of your computer.

If you are using Linux or Mac operating system, you must find out installation instructions by yourself. In both of these operating systems, you can check from Qt’s installing page if there is a suitable version for your operating system.

Mac users can find more information from here.

Moreover, note that probably this is not exactly the same version of Qt Creator and C++ compiler as has been installed in remote desktop. So, there can be differences.

It is a good idea to test the assignments on the remote desktop before submitting them, since they will be tested in the same Linux environment by the course personnel. This is important, because it is possible that a program does not work in the same/correct way in different operating systems or in different versions of them.

Caution

In the end part of the course, you will need valgrind tool for detecting errors concerning memory management. Installing this tool in Windows or Mac computers can be difficult, or even impossible. However, this will not prevent passing the course.

Instructions to install Qt Creator in Windows

If you are installing Qt Creator in your own computer, especially in Windows you should install also Git Bash. This enables you to use command line in the same way as in Linux remote desktop. (Windows has a command line of its own, but it does not support Git commands, and thus, it is better to install Git Bash.)

The instructions below are valid for Windows, but you can check from the link given in the first step, if you can start, even if you have another operating system.

To install Qt Creator to your own computer follow the steps below. To get Qt Creator to be installed, remember to check this choice.

  1. Download the Qt online installer from this link. The site should automatically offer you the right installer, depending on your operating system.

  2. Run the Qt installer.

  3. Create a Qt account and log in by clicking next. Proceed with the installation as you prefer, for example, as follows.

    Screenshot on logging in
    Screenshot on logging in
    Screenshot on logging in
    Screenshot on logging in
  4. Finally, you should encounter the following window. Select Custom installation.

    Screenshot on the final phase of logging in
  5. In the component selection window, select Latest releases. Close the Preview and Additional libraries drop menus. Open the Qt drop menu. Choose the latest 5th version. (It is better to not choose 6th version, because then you will have a newer version than used in automated tests.)

    Screenshot on version selection
  6. Under Qt 5.15.2, select at least the MinGW 8.1.0 64-bit component. (In the figure, Qt Charts component has been selected as well, but it is not necessary).

    Screenshot on version selection
  7. Under Developer and Designer Tools, select the MinGW 8.1.0 64-bit component.

    Screenshot on version selection
  8. Proceed with the installation. This might take a long time (up to hours), but the installation should complete regardless.

  9. When the installation is ready, you may run Qt Creator to verify that the installation was successful. The window should look something like the following.

    Screenshot on succesful installation