Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ CLion和Qt5:调优qmake_C++_Qt_Cmake_Qt5_Clion - Fatal编程技术网

C++ CLion和Qt5:调优qmake

C++ CLion和Qt5:调优qmake,c++,qt,cmake,qt5,clion,C++,Qt,Cmake,Qt5,Clion,我有其他地方解释过的设置,例如。我已在系统范围内安装了Qt5, 并且在myCMakeLists.txt中有必要的行。我的IDE是Clion。 在我添加Q_OBJECT宏之前,简单GUI中的一切都很正常(我希望它将信号连接到插槽)。现在,当我这样做时,我得到了对vtable的未定义引用, 这在网上也有很多。 我的困惑源于这样一个事实:一些人建议在您的项目中使用Qt5-bundlecmake, 这本质上意味着“仅用于GUI”,我需要更改工具链。但实际上有些人对此只字不提。我想说的是 每次添加/删除Q

我有其他地方解释过的设置,例如。我已在系统范围内安装了
Qt5
, 并且在my
CMakeLists.txt
中有必要的行。我的IDE是Clion。 在我添加
Q_OBJECT
宏之前,简单GUI中的一切都很正常(我希望它将信号连接到插槽)。现在,当我这样做时,我得到了对vtable的
未定义引用,
这在网上也有很多。
我的困惑源于这样一个事实:一些人建议在您的项目中使用
Qt5
-bundle
cmake
, 这本质上意味着“仅用于GUI”,我需要更改工具链。但实际上有些人对此只字不提。我想说的是

每次添加/删除Q_对象时,Qt都会运行qmake

现在,如何在我的
CMakeLists.txt
中捕获它其相关部分如下所示。 我在
/usr/lib/qt5/bin
中看到了
moc
qmake
;那么如何将此信息传达给
CLion

# ----- GUI part -----
# Qt5 inclusion
# The meta object compiler is one of the core functionality of Qt, it reads a C++ header file and if it finds a
# Q_OBJECT macro, it will produces a C++ source file containing meta object code for the class.
# It's the mechanism that allow signal and slots to work.
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# set(CMAKE_PREFIX_PATH $ENV{QT_DIR}/$ENV{QT_VERSION}/gcc_64/lib/cmake)
set(CMAKE_PREFIX_PATH /usr/lib/qt5/bin/)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
# Enable user interface compiler (UIC)
# The user interface compiler is a program that read XML from the .ui file
# generated by Qt Interface Designer and generate C++ code from it.
set(CMAKE_AUTOUIC ON)

if(CMAKE_VERSION VERSION_LESS "3.7.0")
    set(CMAKE_INCLUDE_CURRENT_DIR ON)
endif()

set(CMAKE_MODULE_PATH /usr/lib/qt5)
# @see: https://stackoverflow.com/questions/51994603/cmake-qt5-undefined-reference-to-qprinterqprinterqprinterprintermode
SET(QT5_MODULES Widgets PrintSupport)
find_package(Qt5 COMPONENTS ${QT5_MODULES} REQUIRED)

add_subdirectory(${PROJECT_SOURCE_DIR}/extern/qcustomplot)
add_executable(gui
        ${PROJECT_SOURCE_DIR}/gui/main.cpp
        ${PROJECT_SOURCE_DIR}/extern/qcustomplot/qcustomplot.cpp)
set_target_properties(gui PROPERTIES LINKER_LANGUAGE CXX)
target_link_libraries(gui
        PUBLIC
        Qt5::Core Qt5::Widgets qcustomplot)
不要介意冗长的评论;我最初的GUI培训是在
JavaSwing
中,我发现它们很有用

编辑:帮助我的是中提到的
qt5\u wrapper\u cpp
东西
Q\u对象
宏需要生成代码。这就是为什么会出现
未定义的引用
异常。我不记得如何为Qt配置cmake项目,但我建议阅读

类似于
set\u target\u属性(${PROJECT\u NAME}properties AUTOMOC TRUE)
的内容应该对您有所帮助