Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. Compile with msvc
Forum Updated to NodeBB v4.3 + New Features

Compile with msvc

Scheduled Pinned Locked Moved Unsolved Installation and Deployment
2 Posts 2 Posters 479 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sybe
    wrote on 12 Apr 2022, 15:02 last edited by
    #1

    Hello,

    I have developed a c++ project in console and compile it with a cmakelist.txt file and msvc compiler.
    It works good.
    Now I want to add a UI with QT.
    I would like to know if it is possible to compile my qt project and my c++ project with only msvc ?
    Or if I need to use mingw for QT ?

    Here this is my cmakelist.txt :

    cmake_minimum_required(VERSION 3.5)
    project(UI VERSION 0.1 LANGUAGES CXX)
    
    project(myProject)
    cmake_minimum_required(VERSION 3.21)
    
    if (MSVC)
        add_compile_options(
            /W4                         # AllWarnings
            $<$<CONFIG:DEBUG>:/MTd>)    # C++ debug redistributable static link
    else()
        add_compile_options(-Wall -Wextra -pedantic)
    endif()
    
    add_subdirectory(src)
    
    add_executable(myProject)
    
    target_sources(myProject PRIVATE src/main.cpp)
    
    set(CMAKE_INCLUDE_CURRENT_DIR ON)
    
    set(CMAKE_AUTOUIC ON)
    set(CMAKE_AUTOMOC ON)
    set(CMAKE_AUTORCC ON)
    
    set(CMAKE_CXX_STANDARD 17)
    set(CMAKE_CXX_STANDARD_REQUIRED ON)
    
    find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets LinguistTools)
    find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets LinguistTools)
    
    set(TS_FILES UI_fr_FR.ts)
    
    set(PROJECT_SOURCES
            UI/main.cpp
            UI/mainwindow.cpp
            UI/mainwindow.h
            UI/mainwindow.ui
            UI/${TS_FILES}
    )
    
    if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
        qt_add_executable(UI
            MANUAL_FINALIZATION
            ${PROJECT_SOURCES}
        )
    # Define target properties for Android with Qt 6 as:
    #    set_property(TARGET UI APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
    #                 ${CMAKE_CURRENT_SOURCE_DIR}/android)
    # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
    
        qt_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})
    else()
        if(ANDROID)
            add_library(UI SHARED
                ${PROJECT_SOURCES}
            )
    # Define properties for Android with Qt 5 after find_package() calls as:
    #    set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
        else()
            add_executable(UI
                ${PROJECT_SOURCES}
            )
        endif()
    
        qt5_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})
    endif()
    
    target_link_libraries(UI PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
    
    #set_target_properties(UI PROPERTIES
    #    MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
    #    MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
    #    MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
    #    MACOSX_BUNDLE TRUE
    #    WIN32_EXECUTABLE TRUE
    #)
    
    if(QT_VERSION_MAJOR EQUAL 6)
        qt_finalize_executable(UI)
    endif()
    
    

    I tried to compile with the msvc compiler on vs code, I have this erreor :

    Building Custom Rule C:/gitdir/myProject /CMakeLists.txt
    [build]   mocs_compilation_Debug.cpp
    [build] C:\Qt\6.2.4\mingw_64\include\QtCore/qglobal.h(94,1): fatal error C1189: #error:  "Qt requires a C++17 compiler, and a suitable value for __cplusplus. On MSVC, you must pass the /Zc:__cplusplus option to the compiler." [C:\gitdir\myProject\build\UI.vcxproj]
    [build]   main.cpp
    [build] C:\Qt\6.2.4\mingw_64\include\QtCore/qglobal.h(94,1): fatal error C1189: #error:  "Qt requires a C++17 compiler, and a suitable value for __cplusplus. On MSVC, you must pass the /Zc:__cplusplus option to the compiler." [C:\gitdir\myProject\build\UI.vcxproj]
    [build]   mainwindow.cpp
    [build] C:\Qt\6.2.4\mingw_64\include\QtCore/qglobal.h(94,1): fatal error C1189: #error:  "Qt requires a C++17 compiler, and a suitable value for __cplusplus. On MSVC, you must pass the /Zc:__cplusplus option to the compiler." [C:\gitdir\myProject\build\UI.vcxproj]
    [build]   Génération de code en cours...
    [build]   myProject .vcxproj -> C:\gitdir\myProject \build\Debug\myProject .exe
    

    And I tried to compile on QT too, and I have this error :

    Could not find a package configuration file provided by "QT" with any of the following names: Qt6Config.cmake qt6-config.cmake Qt5Config.cmake qt5-config.cmake Add the installation prefix of "QT" to CMAKE_PREFIX_PATH or set "QT_DIR" to a directory containing one of the above files.  If "QT" provides a separate development package or SDK, be sure it has been installed.
    

    Do you have any idea to make my program and compilation work ?

    Thank you in advance for your response

    1 Reply Last reply
    0
    • V Offline
      V Offline
      VRonin
      wrote on 12 Apr 2022, 15:42 last edited by
      #2

      What version of MSVC are you using?

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      0

      1/2

      12 Apr 2022, 15:02

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved