[Qt]cmake下Qt隐藏console的窗口

最近在用Qt写一个GUI,最后release之后发现,伴随窗口启动的还有一个console窗口

我用的是mingw+cmake的编译方法,查了很多资料终于找到了解决方法,如下:

在CMakeList.txt中添加,然后console窗口就不见啦

#隐藏console
if(WIN32)
        if(MSVC)
                set_target_properties(${PROJECT_NAME} PROPERTIES
                        WIN32_EXECUTABLE YES
                        LINK_FLAGS "/ENTRY:mainCRTStartup"
                )
        elseif(CMAKE_COMPILER_IS_GNUCXX)
                        SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mwindows") # Not tested
        else()
                message(SEND_ERROR "You are using an unsupported Windows compiler! (Not MSVC or GCC)")
        endif(MSVC)
elseif(APPLE)
        set_target_properties(${PROJECT_NAME} PROPERTIES
                        MACOSX_BUNDLE YES
        )
elseif(UNIX)
        # Nothing special required
else()
        message(SEND_ERROR "You are on an unsupported platform! (Not Win32, Mac OS X or Unix)")
endif(WIN32)

 

posted @ 2021-04-23 11:04  leeli73  阅读(1829)  评论(0编辑  收藏  举报