Yunfi

Yunfi

tg_channel
github
email

Writing Qt programs with CLion Configuration Guide

Although CLion is not a good choice for writing Qt programs, it can still be used by those who are accustomed to JetBrains IDEs.

Environment used by the author:

  • Windows 11 22H2
  • Qt 5.15.2
  • CLion 2022.3.1

Preparations#

1. Download CLion#

No need to elaborate.
College students can apply for free use, see JetBrains Student Products for details.

2. Download Qt#

  1. Since Qt no longer provides offline installers for individual users, you can only download the online installer from here, and select the version corresponding to your system.
  2. Register a Qt account, agree to the open source obligation, wait, and select the installation directory.
  3. When selecting components: (refer to the image)
    1. First filter on the right side, select only LTS.
    2. For Qt Design Studio, I selected version 3.9.0, although it seems unnecessary, it's still good to have one selected.
    3. Under the Qt directory, select Qt 5.15.2. I chose both the 32-bit and 64-bit versions of MingGW, but MSVC is also fine. Choose the rest according to your needs.
    4. Under Developer and Designer Tools, select QtCreator and a few others, CMake, and Ninja must be selected. The main functions of the options are as follows (source unknown, accuracy unknown):
      1. CDB Debugger (command line debugger): Console debugger, the native debugger of MSVC in Qt. If you choose it, you need to check it. If you choose MinGW, it is not necessary because MinGW has the GDB debugger.
      2. MingGW: The MingGW here is used for cross-compilation, generating executable code on one platform for another platform.
      3. Strawberry Perl: Perl language tools.
        Qt Installation
  4. Follow the instructions next.
  • It doesn't matter if you miss any components, you can find MaintenanceTool.exe in the installation directory to make changes.

Configuration#

You can refer to JetBrains' documentation Qt projects | CLion Documentation (jetbrains.com) for more information.

  1. Open CLion, create a new project -> Qt Widgets Executable.
  2. Fill in the location and C++ standard by yourself, select Qt version 5.
  3. Qt CMake prefix path: Fill in "%qt installation path%/version number/compiler folder".
    • For example, mine is "C:/Environments/qt/5.15.2/mingw81_64"; the example given by JetBrains is "C:\Qt\Qt5.14.0\5.14.0\mingw73_32\".
    • No need for double quotes, using / or \ should be fine, if not, try the other one.
  4. After clicking OK, CLion will automatically generate a sample code and a CMakeList.txt. You can run it directly. If it doesn't work, you can reload the CMake project.

Reload CMake

  • If it still doesn't work, check if you did the third step correctly. If you set the prefix path incorrectly at the beginning, I think the best way is to create the project again.

External Tools#

  • Using QtCreator, you can easily edit .ui and .qrc files. Our goal is to use it to edit Qt-specific file types.
  • Open File -> Settings -> Tools -> External Tools, and create a new entry.
    External Tools
    Change the link of "Program" to the location of your QtCreator.
  • In the future, to edit .ui or .qrc files, right-click on them, go to External Tools -> QtCreator.

Others#

  • If you still have problems, you can refer to the JetBrains documentation mentioned above. It describes the process of using CLion to write Qt programs more thoroughly.
  • I won't mention the advantages of using CLion to write cpp programs. For Qt, the biggest headache for CLion is that its built-in debugging tool cannot display the content of Qt data types, such as QString and QList. For QString, qDebug() cannot output during debugging. A clumsy method is to use the toStdString method of QString to view the value through the debugging tool.
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.