clion qt5安装_在Clion中使用Qt

本文介绍了如何在Clion IDE中使用Qt库进行编译。主要内容包括修改CMakeLists.txt文件,添加必要的Qt5包如Qt5Core、Qt5Widgets和Qt5Gui,并通过qt5_use_modules链接所需模块。适用于Manjaro Linux环境下不会配置CMake的开发者。
摘要由CSDN通过智能技术生成

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()

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).

P.S: my current OS is manjaro 0.8.13 and all I could find was explaining configurations in windows environment so I was unable to implement those tutorials.

解决方案

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 )

and then

qt5_use_modules( MyTest Core Widgets Gui )

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值