/occQt

Primary LanguageC++

QT + OpenCASCADE + CMake

1. mingw编译OpenCASCADE
  • 安装MSYS2

  • 创建make.bat

    • msys2bin下(如C:\msys64\mingw64\bin)创建make.bat,内容如下:

      @echo off
      "C:\msys64\mingw64\bin\mingw32-make.exe" %1 %2 %3 %4 %5 %6 %7 %8 %9

      注意:启动mingw32-make.exe的路径根据实际安装目录修改

  • 编译OpenCASCADE

2. QT项目CMakeLists.txt
  1. 使用Qt Creator创建项目,使用CMAKE配置

  1. vs code的cmake工具使用Qt安装的cmake工具,settings.json

    {
      "cmake.cmakePath": "C:/Qt/Tools/CMake_64/bin/cmake.exe",
      "C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
      "files.associations": {
        "qtranslator": "cpp",
        "qapplication": "cpp",
        "qmainwindow": "cpp",
        "qopenglwidget": "cpp"
      }
    }
  2. 设置环境变量QT_DIRQT_DIR=C:/Qt/6.4.1/mingw_64

  3. 设置QT资源文件

    # 设置自动生成ui.h文件
    set(CMAKE_AUTOUIC ON)
    # 设置自动生成moc文件
    set(CMAKE_AUTOMOC ON)
    # 设置自动处理.qrc文件
    set(CMAKE_AUTORCC ON)
    
    set(RCC_FILES occqt.qrc)
  4. 项目引入QT

    find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets OpenGLWidgets)
    find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets OpenGLWidgets)
  5. 项目引入OpenCASCADE

    set(CAS_ROOT "C:\\Program Files (x86)\\OCCT")
    set(OpenCASCADE_DIR ${CAS_ROOT}/cmake)
    find_package(OpenCASCADE REQUIRE)
    include_directories(${OpenCASCADE_INCLUDE_DIR})
  6. 执行程序引入资源文件和依赖库

    add_executable(occQT
                ${PROJECT_SOURCES}
                ${RCC_FILES}   
      )
    
    target_link_libraries(
        occQT PRIVATE 
        Qt${QT_VERSION_MAJOR}::Widgets 
        Qt${QT_VERSION_MAJOR}::OpenGLWidgets 
        ${OpenCASCADE_LIBRARIES}
    )