要查看代码: 我在https://github.com/jaysimon/clion_qtcreator
上创建了一个存储库我成功地在qt Creator中创建了一个演示ui,但在失败时却使用了相同的代码。 我知道了:
[ 16%] Automatic MOC and UIC for target 20190314_clion_qt
[ 16%] Built target 20190314_clion_qt_autogen
[ 33%] Linking CXX executable 20190314_clion_qt
CMakeFiles/20190314_clion_qt.dir/src/mainwindow.cpp.o: In function `MainWindow::MainWindow(QWidget*)':
/home/hw/01-workspace/20190314_clion_qt/src/mainwindow.cpp:7: undefined reference to `vtable for MainWindow'
/home/hw/01-workspace/20190314_clion_qt/src/mainwindow.cpp:7: undefined reference to `vtable for MainWindow'
CMakeFiles/20190314_clion_qt.dir/src/mainwindow.cpp.o: In function `MainWindow::~MainWindow()':
/home/hw/01-workspace/20190314_clion_qt/src/mainwindow.cpp:30: undefined reference to `vtable for MainWindow'
/home/hw/01-workspace/20190314_clion_qt/src/mainwindow.cpp:30: undefined reference to `vtable for MainWindow'
collect2: error: ld returned 1 exit status
CMakeFiles/20190314_clion_qt.dir/build.make:131: recipe for target '20190314_clion_qt' failed
make[3]: *** [20190314_clion_qt] Error 1
CMakeFiles/Makefile2:72: recipe for target 'CMakeFiles/20190314_clion_qt.dir/all' failed
make[2]: *** [CMakeFiles/20190314_clion_qt.dir/all] Error 2
CMakeFiles/Makefile2:84: recipe for target 'CMakeFiles/20190314_clion_qt.dir/rule' failed
make[1]: *** [CMakeFiles/20190314_clion_qt.dir/rule] Error 2
Makefile:118: recipe for target '20190314_clion_qt' failed
make: *** [20190314_clion_qt] Error 2
您可以帮助它与CMake成功运行吗? 推送请求是最好的。
CMakeList.txt:
cmake_minimum_required(VERSION 3.0)
project(20190314_clion_qt)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
find_package(Qt5Core REQUIRED)
find_package(Qt5Gui REQUIRED)
find_package(Qt5Widgets REQUIRED)
include_directories(./inc)
set(SOURCE_CODE
src/main.cpp
src/mainwindow.cpp
src/deal.cpp)
add_executable(${PROJECT_NAME} ${SOURCE_CODE})
target_link_libraries(${PROJECT_NAME} -pthread Qt5::Core)
target_link_libraries(${PROJECT_NAME} Qt5::Gui)
target_link_libraries(${PROJECT_NAME} Qt5::Widgets)
main.cpp:
#include "mainwindow.h"
#include <QApplication>
#include "deal.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
pthread_t tid;
pthread_create(&tid, NULL, run, NULL);
//pthread_exit(&tid);
return a.exec();
}