29

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.

user2180248
  • 303
  • 1
  • 3
  • 7
  • 4
    Why would you want to do that? I mean VS is clumsy without Visual Assist X, which doesn't work with Express either. With Qt Creator you get excellent autocomplete and a ton of time savers - generate accessors for properties, generate definitions from declarations and so on... Plus VS doesn't support QML at all. You can still use the VS compiler from Creator. Overall, I see no good reason to chose VS Express. – dtech Mar 17 '13 at 20:42
  • 9
    @ddriver One good reason is if you already have a Visual Studio solution, and wish to add a QT project to it, without having to have two separate IDEs and maintain two sets of settings. – JBentley Oct 09 '13 at 13:34

4 Answers4

24

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
Community
  • 1
  • 1
Linville
  • 3,613
  • 1
  • 27
  • 41
3

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.

drescherjm
  • 10,365
  • 5
  • 44
  • 64
  • I've got checked "CMakeProjectManager" in QtCreator under "Installed plugins". How do I create a new project for VS and then compile it with CMake? – user2180248 Mar 19 '13 at 20:07
  • I am not sure what the CMake QtCreator plugin contains. The official download for CMake is here: http://www.cmake.org/cmake/resources/software.html. As for how to get started you need to create a CMakeLists.txt file for you application and use CMake to generate the Visual Studio solution instead of doing this in the Visual Studio GUI. – drescherjm Mar 19 '13 at 21:35
2

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.

meyumer
  • 5,063
  • 1
  • 17
  • 21
-2

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.

lmedinas
  • 314
  • 2
  • 13