最近需要使用Qt,于是随手将一些零散点滴内容记录下来备忘。
首先第一步,就是建立CMakeLists工程。
例子如下:
cmake_minimum_required(VERSION 3.22) project(otbox) set(CMAKE_C_STANDARD 99) set(CMAKE_CXX_STANDARD 14) #包含当前目录 set(CMAKE_INCLUDE_CURRENT_DIR ON) #调用moc,uic,rcc编译qt set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_AUTOUIC ON) set(QT_VERSION 6) #设置qt的cmake目录 #这个目录包含了所有qt模块编译所需的cmake文件 set(CMAKE_PREFIX_PATH /usr/local/opt/qt6/bin/) find_package(Qt6 COMPONENTS Core Gui Widgets REQUIRED) include_directories(${PROJECT_SOURCE_DIR}/include) #包含需要编译的文件 set(SOURCE_FILES main.cpp ) #set(RESOURCE_FILES main.qml) #set(QRC_FILES qml.qrc) #add_executable(${PROJECT_NAME} WIN32 ${SOURCE_FILES} ${RESOURCE_FILES} ${QRC_FILES}) add_executable(${PROJECT_NAME} ${SOURCE_FILES} ${RESOURCE_FILES} ${QRC_FILES}) target_link_libraries(${PROJECT_NAME} Qt::Core Qt::Gui Qt::Widgets )
main.cpp内容:
1 #include <iostream> 2 #include <QApplication> 3 #include <QPushButton> 4 #include <QObject> 5 6 7 int main(int argc, char * argv[]) { 8 std::cout << "helelo " << std::endl; 9 10 QApplication a(argc, argv); 11 QPushButton button("click me", nullptr); 12 button.resize(100, 80); 13 button.show(); 14 return QApplication::exec(); 15 }
编译可以看见hello界面
标签:Qt6,FILES,CMakeLists,01,CMAKE,SOURCE,set,main,include From: https://www.cnblogs.com/oilamp/p/16967285.html