Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 526
user2180248 Avatar asked Mar 17 '13 20:03

user2180248


People also ask

Can you use Qt with Visual Studio?

In Microsoft Visual Studio, select Extensions > Manage Extensions > Online, and search for Qt Visual Studio Tools to install or update Qt VS Tools.

Can I use Qt without Qt Creator?

You certainly don't have to use QtCreator to write a Qt program. You also don't have to use qmake but you are asking for trouble by not using it. To do anything even remotely interesting in Qt you will inevitably end up subclassing QObject .

Does Qt need Visual Studio?

Yes, it is possible - and it actually also works quite nicely! QT Creator is a full IDE, also containing a compiler (GCC) and a debugger (GDB). Just download it, install it, and you are ready to go. How do you add Zedgraph to Visual Studio?

How do I open Qt Project in Visual Studio code?

To open a QML file you can right-click on the file in the explorer bar or on the file itself when it is open in the VS Code editor, and select Open QML file in Qt Design Studio . This will start an instance of Qt Design Studio ready to edit your file.


1 Answers

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 
like image 148
Linville Avatar answered Sep 23 '22 12:09

Linville