简体   繁体   中英

Setting up a Qt6 project in CLion with CMake

I am trying to make a Qt6 application, however I do not like qtcreator so much so I would like to work in CLion. I have been trying to configure my project with CMake but I am kind of new to all that and I am stuck even though I have followed this "tutorial" on the jetbrains website: https://www.jetbrains.com/help/clion/qt-tutorial.html#configure-cmakelists

Here is my CMakeList.txt file:

cmake_minimum_required(VERSION 3.19)
project(VidShare)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_PREFIX_PATH  "C:/Qt/6.1.1/mingw81_64/lib/cmake/")

find_package(Qt6Widgets REQUIRED)

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)

add_executable(VidShare main.cpp)
target_link_libraries(VidShare Qt6::Widgets)

here is my project structure:

Vidshare
  \--cmake-build-debug   # This was generated by CLion itself
  \--src                 # Currently empty
  CMakeList.txt
  main.cpp

When I click on build I get this message:

CMake Error at CMakeLists.txt:9 (find_package):
  Could not find a configuration file for package "Qt6Widgets" that is
  compatible with requested version "".

  The following configuration files were considered but not accepted:

    C:/Qt/6.1.1/mingw81_64/lib/cmake/Qt6Widgets/Qt6WidgetsConfig.cmake, version: 6.1.1 (64bit)

Like I said I'm new to cmake so this might be some stupid mistakes but I have been at it for too long and my research did not really bring me anywhere. I am using minGW on windows 10 but I doubt this is the issue at the moment. I also thought that maybe I had to put the Qt libraries in my project or something but I don't know which ones or where to put them but my Qt installation folder is in C:\\Qt\\ if that is helpful.

Basically what I want is to setup my environment to be able to work with qt6 in CLion..

Thanks in advance!

After further research I realized I was not using the good version of MinGW (hence the error message). I downloaded the 64bit version of MinGW and tried with that compiler itself and built the project correctly. Moreover I had an issue where it would compile fine but not run and return an error code. I had to put the Qt binaries in my system path variable ( C:\\Qt\\6.1.1\\mingw81_64\\bin ) and I can display a window properly with this test code:

#include <QApplication>
#include <QLabel>

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM