在Clion中使用Qt

编程入门 行业动态 更新时间:2024-10-24 18:17:51
本文介绍了在Clion中使用Qt的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图使用Clion IDE编译一个简单的程序使用Qt库,但我不知道如何配置 CMakeLists.txt 文件。 (我不熟悉cmake和工具链)这是我当前的 CMakeLists.txt 文件:

I'm trying to use Clion IDE to compile a simple program using Qt library, but I can't figure out how to configure CMakeLists.txt file. (I'm not familiar with cmake and toolchain) this is my current CMakeLists.txt file:

cmake_minimum_required(VERSION 3.2) project(MyTest) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") set(SOURCE_FILES main.cpp) add_executable(MyTest ${SOURCE_FILES}) # Define sources and executable set(EXECUTABLE_NAME "MySFML") add_executable(${EXECUTABLE_NAME} main.cpp) # Detect and add SFML set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules" ${CMAKE_MODULE_PATH}) find_package(SFML 2 REQUIRED system window graphics network audio) if(SFML_FOUND) include_directories(${SFML_INCLUDE_DIR}) target_link_libraries(${EXECUTABLE_NAME} ${SFML_LIBRARIES}) endif()

配置为使用SFML库与FindSFML .cmake文件,它工作正常。 (我已经从一些教程复制这些文件)现在我想要一些帮助关于正确的 CMakeLists.txt 配置编译使用Qt库的程序(更有助于如果文件和

It's configured to use SFML library with a "FindSFML.cmake" file and it works fine. (I have copied these files from some tutorial) now I want some help regarding proper CMakeLists.txt configuration to compile programs that are using Qt library (it's more helpful if the files and explanations are provided).

推荐答案

CMake 项目文件缺少Qt包。您必须添加:

Your CMake project file is missing the Qt packages. You have to add:

find_package( Qt5Core REQUIRED ) find_package( Qt5Widgets REQUIRED ) find_package( Qt5Gui REQUIRED )

,然后

qt5_use_modules( MyTest Core Widgets Gui )

更多推荐

在Clion中使用Qt

本文发布于:2023-10-25 22:19:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1528268.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Clion   Qt

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!