C++ 在没有插件的情况下将 Qt 与 Visual Studio 结合使用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15465932/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using Qt with Visual Studio without add-in
提问by user2180248
I recently started using Qt library and I've got a question. Is this possible to use Qt with Visual Studio without special add-in?
我最近开始使用 Qt 库,我有一个问题。这是否可以在没有特殊加载项的情况下将 Qt 与 Visual Studio 一起使用?
I want to just design the UI using qt designer and do the rest in VS Express. How do I do that?
我只想使用 qt 设计器设计 UI,然后在 VS Express 中完成其余的工作。我怎么做?
Thanks.
谢谢。
采纳答案by Linville
Yes you can, if you would prefer not to use the QtVSAddinit is very easy to use Qt with VS Express without the VS add-in and without having to do any of the uic or mocsteps manually. 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. Whenever you make a change like adding/removing a form or source, modify the qmake project file and regenerate the VS project. Don't modify the VS project file at all, treat it only as a temporary item. QMake will add the rules automatically to the VS project file to rerun uicand moc, you don't need to do anything if you're just modifying source code or forms.
是的,您可以,如果您不想使用QtVSAddin,那么在没有 VS 插件的情况下将 Qt 与 VS Express 一起使用非常容易,也无需手动执行任何 uic 或 moc步骤。让 QMake(与 Qt 一起安装,但不是 QtVSAddin 的一部分)创建您的 VS 项目文件,并在 qmake 项目文件中完成所有项目设置。每当您进行添加/删除表单或源等更改时,请修改 qmake 项目文件并重新生成 VS 项目。完全不要修改VS项目文件,只把它当作一个临时项。QMake 会自动将规则添加到 VS 项目文件中以重新运行uic和moc,如果您只是修改源代码或表单,则无需执行任何操作。
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 默认生成生成文件)。
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). 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.
此外,使用批处理文件重新运行 qmake 很方便,因此您不必打开命令提示符并设置环境(或在已经设置环境的命令提示符中将目录更改为您的项目)。如果您还没有在 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
回答by drescherjm
CMake is also an answer and it does work with express versions of 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. I install the addon just for the debug expansion that comes in the same package.
CMake 也是一个答案,它确实适用于 Visual Studio 的快速版本。我的意思是,如果您在 CMake 中使用 Qt 支持,您可以在 Visual Studio 中开发 Qt 项目(就像我多年来所做的那样)而无需 Qt 插件。我只为同一个包中的调试扩展安装插件。
回答by meyumer
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.
这当然是可能的,但没有加载,你需要UI
和MOC
你之前无论是所需的文件编译VS内休息,或通过预编译脚本。
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.
该加载项可帮助您在编译其余文件之前在所需文件上顺利调用这些文件。