Using Qt5 with CLion and having this problem
Solved
General and Desktop
-
So since my QtCreator syntax highlighting doesn't work, I decided to try out CLion.
Here's my cmake file:
cmake_minimum_required(VERSION 3.1.0) project(untitled) set (CMAKE_PREFIX_PATH "/Users/fuchsiaff/Qt/5.12.0/clang_64") set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") # Find includes in corresponding build directories set(SOURCE_FILES main.cpp mainer.cpp mainer.h) add_executable(untitled ${SOURCE_FILES}) set(CMAKE_INCLUDE_CURRENT_DIR ON) # Instruct CMake to run moc automatically when needed set(CMAKE_AUTOMOC ON) # Create code from a list of Qt designer ui files # Find the QtWidgets library find_package(Qt5 REQUIRED COMPONENTS Core Widgets Gui) # Use the Widgets module from Qt 5 target_link_libraries(untitled Qt5::Core Qt5::Widgets Qt5::Gui)
The program compiles just fine when there are no class definitions but as soon as I add Mainer.h and Mainer.cpp to my code
Mainer.h :
#ifndef MAINER_H #define MAINER_H #include <QWidget> class mainer : public QWidget { Q_OBJECT public: explicit mainer(QWidget *parent = nullptr); signals: public slots: }; #endif // MAINER_H
Mainer.cpp :
#include "mainer.h" mainer::mainer(QWidget *parent) : QWidget(parent) { }
And after trying to compile that, I get this error:
[ 33%] Linking CXX executable untitled Undefined symbols for architecture x86_64: "vtable for mainer", referenced from: mainer::mainer(QWidget*) in mainer.cpp.o NOTE: a missing vtable usually means the first non-inline virtual member function has no definition. ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) make[3]: *** [untitled] Error 1 make[2]: *** [CMakeFiles/untitled.dir/all] Error 2 make[1]: *** [CMakeFiles/untitled.dir/rule] Error 2 make: *** [untitled] Error 2
-
@Fuchsiaff said in Using Qt5 with CLion and having this problem:
add_executable
move this after setting automoc option - otherwise automoc is not enabled I would guess
-
-
@Fuchsiaff Have you got good experience in using CLion with QT? I've got a lot of troubles with QT Creator only for last month dozen of crashes and broken highlighting. I am seeking alternative because there are always something wrong with Qt Creator.