简体   繁体   中英

Using Qt with Visual Studio without add-in

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?

I want to just design the UI using qt designer and do the rest in 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. 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 uic and moc , you don't need to do anything if you're just modifying source code or forms.

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 ).

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).

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.

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. 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.

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.

Specifically:

uic generates the headers from .ui files.

and

moc generates the additional implementation files for classes that has Qt macros in it.

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.

But it's too much work and you can use QtCreator which is an amazing light IDE.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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