CUEH Development Environment Guides
Installing Qt

Installing Qt

As part of the programming module you study on the course, you will be tasked with using the C++ programming language to complete lab activities and assessments. For the assessment, you will be required to implement a graphical user interface, and the framework of choice for this module is Qt.

In this guide, you shall be taken through the journey of installing the Qt framework for a Linux (Debian-based) operating system.

Downloading and Installing the Qt Framework

As it is, a Linux distribution such as Ubuntu or Linux Mint, do not come installed with the Qt frameowkr. Therefore, to install this frameowork you will need to use the command-line interface. To open the Terminal window, you will need to search for Terminal in the Application screen, or use the keyboard shortcut: Ctrl + Alt + T,

With the command-line window open, you can install the necessary libraries by using the following command:

$ sudo apt install qtcreator qt6-base-dev

Important

Remember that the sudo command is used to elevate privileges. In this instance, the apt command requires administrator privileges to install the necessary tools/libraries for Qt.

When this command is entered in the command-line interface window, you will see a question is asked whether you wish to proceed with the installation. Enter Y into the command-line interface window and push Enter on the keyboard. Once the command has been executed, this will begin the process of installing the necessary libraries and tools for Qt to run on your system.

Checking the Qt Install

To confirm whether you have installed the Qt framework correctly, you can run the C++ script provided below. The outcome of this script should display a label saying: "Hello CUEH!" in a QApplication window.

#include <QApplication>
#include <QLabel>

int main(int argc, char *argv[]) {
    QApplication a(argc, argv);
    QLabel label("Hello CUEH!", nullptr);
    label.resize(200, 100);
    label.show();
    return QApplication::exec();
}

If you are using the JetBrains CLion IDE, you will need to modify the CMakeLists.txt file so it looks like the one below:

cmake_minimum_required(VERSION 3.29)
project(My_First_Project)

set(CMAKE_CXX_STANDARD 23)

find_package(Qt6 COMPONENTS Core Gui Widgets REQUIRED)

add_executable(My_First_Project main.cpp)
target_link_libraries(My_First_Project Qt::Core Qt::Gui Qt::Widgets)

The differences compared to the normal CMakeLists.txt file are the following lines:

  • find_package(Qt6 COMPONENTS Core Gui Widgets REQUIRED): finds and configures the Qt6 libraries (Core, Gui, and Widgets), ensuring they are available and marking them as mandatory for the build
  • target_link_libraries(My_First_Project Qt::Core Qt::Gui Qt::Widgets): links the My_First_Project target to the Qt libraries Qt::Core, Qt::Gui, and Qt::Widgets

Hopefully, once you have compiled and built your script a graphical user interface should pop-up with a label saying: Hello CUEH!.

Conclusion

That is the end of this guide on installing the Qt framework. If you have followed all the necessary steps correctly, you should have a fully functional implementation of the OpenCV libraries, bespoke to your machine. This will enable you to complete any necessary programming based lab activities and assessments that you will participate with on this course.

Mistakes or Problems?

If you have spotted any errors or issues within this tutorial, you can e-mail Dr Ian Cornelius. Ensure to include in your message a description of the error or issue and a possible resolution. Also remember to include a URL to the page with the issue or error.