如何在Clion中运行Qt Creator演示代码?

时间:2019-03-14 03:46:00

标签: qt clion

要查看代码: 我在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();
}

1 个答案:

答案 0 :(得分:0)

我解决了它,但是很困惑为什么,这是解决方案,您也可以在github上将其git。

将MainWindow.cpp MainWindow.h MainWindow.ui放到同一目录中,即可解决。 enter image description here enter image description here