简体   繁体   English

Visual Studio 2010 Qt外接程序Cmake项目

[英]Visual Studio 2010 Qt Add-in Cmake Project

I'm trying to use Cmake to start a new Qt Project inside Visual Studio 2010. I want to recreate the standard setup, as if you were just creating a new Qt project inside MSVS using the Qt Add-in. 我正在尝试使用Cmake在Visual Studio 2010中启动新的Qt项目。我想重新创建标准设置,就好像您只是在使用Qt加载项在MSVS中创建新的Qt项目一样。 Since I only have limited knowledge of Cmake and the internet is running out of ideas I need your help. 由于我对Cmake的了解有限,并且互联网上的想法已经用尽,因此需要您的帮助。 The reason why I want to do this is because I have an existing Visual Studio project and I need to add a GUI. 之所以要这样做,是因为我有一个现有的Visual Studio项目,并且需要添加一个GUI。 So what I did was creating a new Qt project inside Visual Studio with just the default Qt-Window. 所以我要做的就是在Visual Studio中使用默认的Qt-Window创建一个新的Qt项目。 What do I need to do in the CmakeLists.txt to achieve the same results? 为了达到相同的结果,我需要在CmakeLists.txt中做什么? Or is it easier not to try to remake the standard project and just use the .ui file from the Designer? 还是不尝试重新制作标准项目而仅使用Designer中的.ui文件会更容易吗? Do I need to do the whole qt5_wrap_cpp, qt4_wrap_ui and so on stuff in the Cmake? 我是否需要在Cmake中完成整个qt5_wrap_cpp,qt4_wrap_ui等工作? I've searched for a solution for about two days now and I'm still there where I started. 我已经搜索了大约两天的解决方案,但我仍然在这里开始。

Thanks for your help and guidance 感谢您的帮助和指导

I am also doing similar things, so I would like to share some views on it. 我也在做类似的事情,所以我想对此发表一些看法。

I created a project in QtCreator, with a project file .pro , .h , .cpp , .ui files. 我在QtCreator中创建了一个项目,其中包含项目文件.pro.h.cpp.ui文件。 The qt project file .pro is for qmake. qt项目文件.pro用于qmake。 Then I transferred my project to MSVC. 然后,我将项目转移到MSVC。 All I do is to transfer the .h .cpp .ui files to a new directory, and add a CMakeList.txt there. 我要做的就是将.h .cpp .ui文件传输到新目录,然后在其中添加CMakeList.txt

If you have a existing Visual Studio project and you need to add a GUI, you can create a .ui in QtDesigner and add the .ui file to CMakeList.txt . 如果您已有一个Visual Studio项目,并且需要添加GUI,则可以在QtDesigner中创建一个.ui并将该.ui文件添加到CMakeList.txt

To create CMakeList.txt , you can go to the link in the comment above. 要创建CMakeList.txt ,您可以转到上面评论中的链接。 Though I found the web quite hard to understand as a newbie. 尽管我发现新手很难理解网络。 So basically, the CMakeList.txt would contain: 因此,基本上,CMakeList.txt将包含:

Follow the qt web for details when including the directories.
After that: 

SET( PROJECT_SRCS
     main.cpp)

SET( PROJECT_UIS                     //this is where you include your .ui files
     Resources/UI/myui.ui)

SET( PROJECT_MOC_HDRS
       mainWindow.h)

QT5_WRAP_UI( PROJECT_UIS_H            //wrap ui files
             ${PROJECT_UIS}
           )
QT5_WRAP_CPP( PROJECT_MOC_SRCS
              ${PROJECT_MOC_HDRS}
            )
ADD_EXECUTABLE( MRT_1JUL
                ${PROJECT_SRCS}
                ${PROJECT_UIS_H}
                ${PROJECT_MOC_SRCS}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM