简体   繁体   English

在没有加载项的情况下将Qt与Visual Studio一起使用

[英]Using Qt with Visual Studio without add-in

I recently started using Qt library and I've got a question. 我最近开始使用Qt库,我有一个问题。 Is this possible to use Qt with Visual Studio without special add-in? 这是否可以在没有特殊加载项的情况下将Qt与Visual Studio一起使用?

I want to just design the UI using qt designer and do the rest in VS Express. 我想用qt设计器设计UI,然后在VS Express中完成剩下的工作。 How do I do that? 我怎么做?

Thanks. 谢谢。

Yes you can, if you would prefer not to use the QtVSAddin it is very easy to use Qt with VS Express without the VS add-in and without having to do any of the uic or moc steps manually. 是的,你可以,如果你不想使用QtVSAddin ,很容易在没有VS加载项的情况下使用Qt和VS Express,而无需手动执行任何uic或moc步骤。 Let QMake (installed with Qt but not part of the QtVSAddin) create your VS project file and do all your project setup in a qmake project file. 让QMake(与Qt一起安装但不是QtVSAddin的一部分)创建您的VS项目文件,并在qmake项目文件中完成所有项目设置。 Whenever you make a change like adding/removing a form or source, modify the qmake project file and regenerate the VS project. 每当您进行更改(如添加/删除表单或源)时,请修改qmake项目文件并重新生成VS项目。 Don't modify the VS project file at all, treat it only as a temporary item. 根本不要修改VS项目文件,只将其视为临时项目。 QMake will add the rules automatically to the VS project file to rerun uic and moc , you don't need to do anything if you're just modifying source code or forms. QMake会自动将规则添加到VS项目文件中以重新运行uicmoc ,如果您只是修改源代码或表单,则无需执行任何操作。

For configuration management purposes I find this a much cleaner approach to use this workflow as you treat the VS project file as only a temporary item (they tend to diff badly and are a pain to maintain in version control ). 出于配置管理的目的,我发现这是一种更清洁的方法来使用此工作流程,因为您将VS项目文件视为仅一个临时项目(它们往往差异很大,并且在版本控制中维护很难 )。

A couple snippets to help you out: 一对夫妇片段来帮助你:

In your qmake project file ensure you add the following line into it so that VS project files are generated when running on Windows (qmake defaults to generating a makefile). 在qmake项目文件中,确保在其中添加以下行,以便在Windows上运行时生成VS项目文件(qmake默认生成makefile)。

your_qmake_proj.pro your_qmake_proj.pro

win32: TEMPLATE = vcapp

Additionally, it's convenient to have a batch file to rerun qmake so you don't have to bring up a command prompt and set environment up (or change directory to your project in a command prompt that already has the environment setup). 此外,让批处理文件重新运行qmake很方便,因此您不必调出命令提示符并设置环境(或者在已经具有环境设置的命令提示符中将目录更改为项目)。 If you haven't set the various Qt environment variables with Windows (or prefer not to) make sure to add them to your batch file. 如果您尚未使用Windows设置各种Qt环境变量(或者不愿意),请确保将它们添加到批处理文件中。

makevcproj.bat makevcproj.bat

set QTDIR=C:\Qt\x.y.z
set PATH=%PATH%;%QTDIR%\bin
set QMAKESPEC=win32-msvcXXXX
qmake your_qmake_proj.pro
pause

CMake is also an answer and it does work with express versions of Visual Studio. CMake也是一个答案,它适用于Visual Studio的快速版本。 I mean if you use the Qt support in CMake you can develop Qt projects in Visual Studio (like I have done for years) without the Qt Addon. 我的意思是如果你在CMake中使用Qt支持,你可以在没有Qt Addon的情况下在Visual Studio中开发Qt项目(就像我已经做了多年)。 I install the addon just for the debug expansion that comes in the same package. 我安装插件只是为了同一个包中的调试扩展。

It is certainly possible, but without the add-in you will need to UI and MOC the needed files either before you compile the rest within VS, or through pre-compile scripting. 它当然是可能的,但是如果没有加载项,您需要在编译VS中的其余文件之前或通过预编译脚本编写UIMOC所需的文件。

Specifically: 特别:

uic generates the headers from .ui files. uic.ui文件生成标头。

and

moc generates the additional implementation files for classes that has Qt macros in it. moc为其中包含Qt宏的类生成其他实现文件。

The add-in helps you call these smoothly on the required files before compiling the rest. 加载项可帮助您在编译其余文件之前顺利调用所需文件。

It's is possible if you create the UI in QtCreator and manually setup VS in a way that generate the UI and MOC files. 如果您在QtCreator中创建UI并以生成UI和MOC文件的方式手动设置VS,则可以执行此操作。

But it's too much work and you can use QtCreator which is an amazing light IDE. 但它太多的工作,你可以使用QtCreator这是一个惊人的轻型IDE。

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

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