Feature image for the article about how to install Qt5 and Qt Creator on Linux

Install Qt5 and Qt Creator on Linux

Interested in developing a graphical user interface application for Linux? Not sure where to get started? If you know a little C++, you can’t go wrong with using the Qt5 programming library in combination with the Qt Creator integrated development environment. It’s what the entire KDE Plasma desktop environment and all its applications use under the hood. This article explains how to install the Qt5 development packages and the Qt Creator IDE on Debian, Ubuntu, Fedora and openSUSE.

Background

With the Qt5 programming library for C++, you can develop graphical user interface (GUI) application on Linux. Its included Qt Widgets form the primary building blocks for all user interface elements, such as menus, edit boxes, pushbuttons, etc. Qt5 also offers a unique and easy-to-use signals and slots mechanism for event generation and handling.

In case you never heard of Qt5 before, chances are that you, as a Linux desktop user, definitely used Qt5. It’s the foundation of the KDE Plasma desktop environment and all its applications. If you ever worked with Dolphin, Kate, Konsole, Krita or Kdenlive, you’ve used Qt.

In addition to the Qt5 library itself, the creators offer a full featured integrated development environment: Qt Creator. Besides a mature and capable code editor and debugger, it also integrates the Qt Designer application. With Qt Designer you can visually design the user interface of your application’s main window and dialogs. The following screenshot gives you and idea of what the Qt Designer looks like:

Screenshot of what it looks like to visually design a Qt5 widgets based form with the Qt designer, embedded in Qt Creator.

The Qt5 library is cross-platform as well. This means that with little effort, you can rebuild your Linux GUI application on other platforms such as Windows and macOS. For those not too versed in C++, you can opt to develop in a different programming language. Qt language bindings exist for Python, Java, C#, Rust, Go and more.

Installing Qt5 and Qt Creator on Linux can be a bit tricky. Therefore, this article explains how to install the Qt5 development packages and the Qt Creator IDE on popular Linux distributions. We’ll cover Debian, Ubuntu, Fedora and openSUSE. Once installed, I’ll also help you get started with setting up a typical Hello World type GUI application.

What do you need

To follow along with the presented installation instructions of Qt5 and Qt Creator, all you really need is an Ubuntu, Debian, Fedora or openSUSE based Linux system with desktop environment. You can use whichever desktop environment you prefer. If you don’t yet want to install Qt5 and the Qt Creator on your Linux daily driver system, you can always try it out in a virtual machine first. In this case, consider installing openSUSE Tumbleweed in the virtual machine. It’s what I’ll be using for this article as well.

Installation of Qt5 and Qt Creator

Note that Qt Creator and the Qt5 development packages are essentially two separate things. They are often used together, but that’s not a requirement:

  • You can develop Qt5 user interface applications, without using Qt Creator.
  • You can develop C++ applications with Qt Creator, without using the Qt5 programming library.

This is important to understand, because just installing Qt Creator does not always automatically install the Qt5 development packages. In this case this would lead to a No Valid Kits Found error, when trying to create a new QWidgets application project in Qt Creator. The following sections explain how to properly install both the Qt5 development packages and the Qt Creator IDE on commonly used Linux distributions.

Install Qt5 and Qt Creator on openSUSE Tumbleweed and Leap

I’ll start with the openSUSE distributions for two reasons: (1) They are my personal favorites and (2) openSUSE makes it super easy to install Qt5 and Qt Creator. If you prefer installing packages through the Yast Software application, click the ViewPatterns button on the toolbar. The left view now lists all installable patterns. Scroll down to the Development section and check the box next to Qt 5 Development. Finally, click the Accept button in the bottom-right corner to kick off the installation:

Screenshot of the Yast tool, which illustrates how to select Qt5 and Qt Creator for installation on openSUSE Linux.

For those who prefer installing packages in the terminal, run this command:

  • sudo zypper install -t pattern devel_qt5
Terminal screenshot of installing Qt5 and the Qt Creator with zypper on openSUSE Linux.

Install Qt5 and Qt Creator on Fedora

At this point Fedora does not offer a Qt5 development pattern for convenient installation. Not a major concern, because with the help of the wildcard character, you can easily install both the Qt5 development packages and Qt Creator with command:

  • sudo dnf install qt-creator qt5-*-devel qt5-*-doc
Terminal screenshot that shows how to install Qt5 and the Qt Creator with dnf on Fedora Linux.

Install Qt5 and Qt Creator on Ubuntu and Debian

Debian and its derived distributions, such as Ubuntu and the Raspberry PI OS, make installing Qt5 and the Qt Creator a bit trickier. The Apt package manager does not feature a way to install the related packages as a group. Through regular expression patterns, Apt does enable you to install multiple packages in a creative way. However, I did not find a clean way to apply this to the Qt5 and Qt Creator related packages. This only leaves the option of installing all packages individually. For this reason, I’ll split up the installation in two parts:

  1. The essential packages needed to start development of Qt5 based applications.
  2. The extra packages that you might need down the road.

If you want to have everything Qt5 development related installed on your PC, simply complete the installation instructions from both parts.

Run the following command to install the essential packages:

  • sudo apt install qtcreator qtbase5-dev qtchooser qt5-qmake qtbase5-dev-tools cmake
Terminal screenshot that shows how to install Qt5 adn Qt Creator in Ubuntu, Debian and the Raspberry PI operating system, using APT.

And to install the extra packages run this command:

  • sudo apt install libqt5charts5-dev libqt5datavisualization5-dev libqt5gamepad5-dev libqt5gstreamer-dev libqt5networkauth5-dev libqt5opengl5-dev libqt5remoteobjects5-dev libqt5scxml5-dev libqt5sensors5-dev libqt5serialbus5-dev libqt5serialport5-dev libqt5svg5-dev libqt5texttospeech5-dev libqt5virtualkeyboard5-dev libqt5waylandclient5-dev libqt5waylandcompositor5-dev libqt5webkit5-dev libqt5webchannel5-dev libqt5websockets5-dev libqt5webview5-dev libqt5x11extras5-dev libqt5xmlpatterns5-dev

Building your first Hello World Qt5 application with Qt Creator

Let’s take our freshly installed Qt Creator for a spin to create our first Qt5 Widgets based application.

New project wizard

Open up Qt Creator and start the new project wizard by selecting FileNew Project… from the menu. Select the Qt Widgets Application template and continue by clicking the Choose… button at the bottom of the dialog:

Selecting the template in Qt Creator's new project wizard.

The wizard now prompts us to enter a project name and location. You can of course enter what you prefer. I opted for the name QtTest in a directory with the same name, inside my home directory. Once specified, click the Next button for the next step:

Specify the project name and location in Qt Creator's new project wizard.

When asked to specify the build system, my recommendation is to go with CMake. Most C and C++ developers prefer CMake for new projects. However, if you personally prefer Qt’s qmake, select that one. After selecting the build system, click the Next button to move forward:

Selecting the CMake build system in Qt Creator's new project wizard.

On the next screens of the new project wizard, you can simply accept all the defaults and just keep clicking the Next button. The last screen provides and overview with the files that the wizard intends to create for you. Click the Finish button to instruct the wizard the create the project:

Summary screen of Qt Creator's new project wizard. Click the finish button to actually create the project.

Run, build and debug

The three buttons on the bottom left side of the Qt Creator user interface enable you to build, run and debug the application. Go ahead and click the green play button. Qt Creator then builds and runs the application for you. It presents you with an empty application window. Think of it as your empty canvas that serves as a starting point for your own application:

Screenshot of the Qt Creator tool that highlights the buttons for building, running and debugging the Qt5 application.

User interface design with Qt Designer

As a next step, we’ll use the Qt Designer to add a push button and a line edit widget to our application window. Double-click the mainwindow.ui file in the project explorer. This launches the Qt Designer tool, embedded within Qt Creator. Locate the Push Button and Line Edit widgets and drag one of each onto the form of our main window. Afterwards, select the push button on the form, locate its text property and change it to Click me:

Qt Designer screenshot that highlights how to add a push button and a line edit widget to the form of the application's main window.

If you now build and run the application, you’ll see the two newly added widgets on the application. The push button invites you to click on it. However, nothing happens. We’ll take care of that in the next section.

Signals and slots

Each Qt5 widget emits event related signals. For example, if you click on the push button, it emits the clicked() signal. Your application can respond to these events by connecting a slot to the signal. A slot is basically a class method that acts as the event handler for the signal that you connect it to. Let’s try this out.

Select the push button on the form and click on it with your right mouse-button. A context menu appears, where you can select Go to slot…. This opens up the signal selection dialog. On the dialog you can see a list with all the signals that a push button generates. Select the clicked() signal and click the OK button:

Qt Creator dialog box where you select the push button's signal that you want to create a slot (event handler) for. It highlights the clicked() signal.

This automatically creates the on_pushButton_clicked() method, inside our MainWindow class. Add the following implementation:

void MainWindow::on_pushButton_clicked()
{
  ui->lineEdit->setText("Hello World");  
}

Next build and run the application again. If you now click on the push button, you’ll notice that the text Hello World shows up in the line edit widget:

Screenshot of the finished hello world QT5 application.

Wrap up

In this article you learned how to install the Qt5 development packages and the Qt Creator integrated development environment on your Linux PC. All the way up to creating a new project and building a Hello World type user interface application. This completes the tutorial. It’s now up to you to unleash your creativity and build that one application that we all cannot live without.

Note that if you are interested in building cross-platform applications, the articles about Lazarus and wxWidgets might also appeal to you. With Lazarus you can build user interface applications even quicker. The only downside if that you can only use the Object Pascal programming language. From my personal experience, this is definitely worth the effort:

The other contender, wxWidgets, is more along the lines of Qt5. You build your application in C++. It’s not as widely used as Qt5, but comes with more liberate licensing terms:

PragmaticLinux

Long term Linux enthusiast, open source software developer and technical writer.

View all posts by PragmaticLinux →