How to convert a regular win32 (VC++ vcproj) project to a Qt project? - visual-studio

How can I convert existing vcproj files to project files that the QT add-in to Visual Studio recognizes and treats as valid Qt projects?
Should I just bite the bullet and create new projects to replace the old ones, and then add existing code?
I am using QT 4.6 and VS 2008 with Qt Add-in 1.1.2.
Original vcproj files have NOT been generated with QMake.

Using Visual Studio 2010+ it is now possible to convert a project to a Qt Addin project, using the "Convert project to Qt Add-in project" feature of the Qt Addin.
The following steps are from the work around in bug QTVSADDINBUG-27. This was tested with Visual Studio 2010, but should work similarly with new versions:
Right click on your project in "Solution Explorer", click on "Unload Project"
Right click on your project in "Solution Explorer", click on "Edit .vcxproj"
Add line <Keyword>Qt4VSv1.0</Keyword> between the tags <PropertyGroup Label="Globals"> and </PropertyGroup>.
Right click on your project in "Solution Explorer", click on "Reload Project"
Right click on your project in "Solution Explorer", click on "Convert project to Qt Add-in project"
If you have header files in your project you are going to have to follow the instructions in this answer to trigger the generation of moc_* files in the "Generated Files" folder.
For editions of Visual Studio older than 2010 see this work around.

Here's the response from Nokia support engineer, name removed for privacy protection:
Hi,
Thanks for the suggestion. I have
passed it on to our developers who
will consider implementing it for a
future release. You can track it using
the following link:
https://bugreports.qt.io/browse/QTVSADDINBUG-27
Regards,
Support Engineer, Qt Development Frameworks, Nokia
>
Original question
We have quite a few legacy vcproj projects that we wish to add Qt to it.
Currently, we don't have an easy way to convert these legacy vcproj
files into a Qt-enabled vcproj.
What do I mean by Qt-enabled?
On a non-Qt-enabled vcproj, when I right click on the project name
under Solution Explorer, all options related to Qt are all grayed-out.
It would be really useful if Nokia adds this capability to VSTD Add-in.
Stackoverflow fellows, if you would like to see this feature implemented by Nokia, please help vote for it at the link above! =)

I use Qt VS Tools instead of Qt VS Add-in.
Instructions
In the .vcxproj file, make the following modifications:
Add <Keyword>Qt4VSv1.0</Keyword> into <Project><PropertyGroup Label="Globals"> (in accord with Benjamin's answer).
Add the following element into <Project> (the root element):
<ProjectExtensions>
<VisualStudio>
<UserProperties MocDir=".\GeneratedFiles\$(ConfigurationName)" UicDir=".\GeneratedFiles" RccDir=".\GeneratedFiles" lupdateOptions="" lupdateOnBuild="0" lreleaseOptions="" Qt5Version_x0020_x64="5.6-msvc2013_64" MocOptions="" />
</VisualStudio>
</ProjectExtensions>
Note that the value of the attribute Qt5Version_x0020_x64 should match the name of a Qt version in Qt VS Tools. You may set an arbitrary value and then fix it in Qt Project Settings in Visual Studio.
My setup
Visual Studio 2013
Qt VS Tools 2.0.0 Beta (apparently a rebranding of Qt VS Add-in)
Qt 5.6 msvc2013_64
Notes
When I follow Benjamin's answer and try to "Convert project to Qt VS Tools project", Visual Studio gets stuck.
The only Qt specific functionality I've tried with the project is exporting a .pri file.
I have reverse engineered the necessary modifications from a fresh VS project created using the template Qt GUI Application.

Converting a regular VC project to a QT project should be easier and the error message displayed by the Qt plug-in when attempting to add a Qt class to a non-QT project is exceedingly unhelpful especially when considering the actual differences between a Qt .vcprojfile and a non-Qt one are minimal. It is often the case that you have existing legacy code built into libraries and Dll's. During migration to Qt you may wish to add a Qt class to an existing module which was previously a non-Qt project. If the module has relatively few source files you may find it easier to re-create the project as a Qt project. If it has hundreds of source files or is complex in other ways it is often be easier to simply hand edit the .vcproj file. By comparing a regular .vcproj with a Qt one it is easy to see what the differences are:
A Qt project has a Keyword="Qt4VS1.0" immediately before
TargetFrameWorkVersion line near the top of the file.
At the bottom of the file you need to add the required Globals (in
particular QtVersion.Win32)
You will need to add the locations of the Qt header files to the
include paths (for all build configurations). You can do this later
via the visual studio user interface
For an exe or dll you will also need to add the Qt library locations
and library files to the linker options.
You actually only need to do 1 and 2 in a text editor and then you can reload the project in Visual Studio.
After setting up include paths and libraries you should be able to build the project as usual. Next you can add a new Qt class or convert an existing class into a Qt class. To do the latter first remove the source files for the existing class from the project otherwise the Qt add class wizard is likely to complain.
The above steps are intended for experienced users and you should always back up existing projects .vcproj files bfore hand editing. Simple mistakes here can render the file unusable.

More answer from Qt support engineer; I think the first pargraph is helpful as I didn't know that before:
i think this is a misunderstanding
really. If you have a Qt project
generated with the Add-in, then you
can change this project into a qmake
generated Qt project - and vice versa;
If you have a .vcproj that has been
generated by doing qmake -tp vc, then
you can convert this to a Qt Add-in
project.
There is no functionality to convert a
regular win32 project into a Qt
enabled project, so the suggestion
created is still valid, see:
https://bugreports.qt.io/browse/QTVSADDINBUG-27
I can see from the history of this
report that it has been closed and
re-opened again, so I assume there was
a misunderstanding regarding what you
were looking for in the first place.
If you create a .pro for you project
using qmake, then you should be able
to create a .vcproj file using 'qmake
-tp vc' on that .pro file. The qmake manual is available here:
http://doc.qt.io/qt-5/qmake-manual.html
I hope this helps.
Regards,
--
Support Engineer, Qt Development
Frameworks, Nokia

Related

How do I use Qt in my Visual Studio 2015 projects?

We have large project that used .NET Framework for showing forms/windows. Recently I decided to deprecate CLR dependency and move to Qt.
While learning Qt, we've migrated from Visual studio 2013 to 2015 and then I noticed that there is no qt support for MSVC 14 version which vs2015 use.
Additionally, Qt vs addin was not working jn visual studio express/community edition we use. Is there any chance for me to use Qt and qt addin in our projects?
Searching web did not help, and it looks like no one use Qt with latest Visual Studio?
Building
You can use Qt in Visual Studio 2015 without any problems. As already stated in the comments, you have to build it from source but Qt is pretty straightforward to build. You can download the current (5.5) sources here and then follow this step by step example on building it.
I would also suggest reading more about the configure options, this might save you a lot of time. It might possibly save you some external dependencies as well if you skip components you do not need. My configuration for instance contains -skip qtwebkit -skip qtwebchannel so I do not need ruby or python.
I could totally omit step 3 from the link. Just be sure to open the Visual Studio Command Prompt (32/64 is important here) for configure and nmake.
Usage
For Visual Studio 2015, the Qt Add-In is not available anymore. But there is an Extension (Tools > Extensions & Updates) called Qt5Package or QtPackage which has the same functionality. After installing it, you have the Qt entry on your main toolbar where you have to specify a version and the path to the directory where you built it. This version will also be associated with the current project via the same menu.
If you load an existing project, you also have to convert it so the whole Qt functionality is used automatically. You can do this by opening the solution and right click on it; there should be an entry for the conversion to a QtAddin generated project.
I am using Qt 5.5 on Visual Studio 2015 with an old project and it is working without any issues.
As of now, you can just download Qt for Visual Studio 2015. Here.
Qt have finally added support for Visual Studio 2013 and 2015 although it's only in beta right now. See QTVSADDINBUG-404 for progress and read the blog post From Visual Studio Add-In To Qt VS Tools (Beta).
The Qt Windows could be added to the current project by copying all relating necessary files from the Qt stand-alone project to the current project. Specifically, the following steps must be conducted carefully.
Create an example project of Qt inside a Visual C++ project by using a Qt Plugin Program. The windows must be designed inside this project carefully before adding to the existing project.
Inside the existing project, add carefully the file heloqt.cpp, helloqt.h, ui_helloqt.h, qrc_helloqt.cpp, moc_helloqt.cpp in case of the Qt Project having the name of helloqt.
Add some configurations of Additional include directories and Additional library directories and Additional Dependencies into the existing project.
Compile and add some required *.dll files for running the program.
I have to do that because I want to use a graphic user interface in my big project, and this project is too big to be added into the Qt project inside the Visual C++ Studio.

Qt translator in VS 2010 - translation TS file names are put in the .pro file in Qt Creator, how is it done in Visual Studio?

I have code in C++ which needs to work with the Qt translation tools. In Qt Creator I would add
TARGET = translation
TRANSLATIONS = tran_ar.ts tran_en.ts tran_la.ts
into the .pro file. The development is being done in VS 2010 (the Gui is working fine so Qt is integrated). So where do I put this information in Visual Studio 2010?
Try the menu entry of the Qt plugin for VS:
Qt > Add new translation file
Select project and language, VS should then add a blank xxx.ts file to your project under "Localization Files" or some such. The context menu entry for this file contains links to "lupdate" and "lrelease", so I think you don't even need to bother with pro and pri files you wouldn't really use in VS anyway (I checked that the .qm files produced by lrelease appear to contain all translated entries of the .ts files).

using Qt designer in visual studio?

I'm using visual studio 2010, Qt add-in etc all ok, then create new project using Qt add-in... when doubleclicking *.ui (the actual form) file in VS it opens Qtdesigner, then I put some controls on, but that does not change my code at all :/
Qt form is changed it contains those controls but source files are the same as before even after building my project.
I'm I missing something?
I think Qtdesinger shoult put some code for objects which I created using Qtdesigner.
cos without that we must write all the code as if there were no Qtdesigner so Qtdesinger is useles in Visual studio, the same thing we could just do by hand-coding a form interface.
thanks alot.
EDIT:
OK
I've copied this from Qt site:
You are referencing objects from a .ui file...
The Visual Studio code model parser only parses C++ sources, meaning
that widgets or objects defined in .ui files will not be accessible.
To workaround the problem, the Qt Visual Studio Add-in automatically
generates C++ code from the .ui file by saving the file and running
uic on it. This step is done everytime the project is built. If the
code completion does not work, try to rebuild the project. It is
possible that you have to wait some time, before code completion fully
works after updating an .ui file. For more information, you can refer
to the Modifying Project Properties section. It still does not work...
You should refresh the code model, Intellisense. This is done by
opening the solution explorer, invoking the context menu of the
project and activating the item Update Intellisense.
now it looks that I'm having such problems but this does not help at all, update intelisece. I can't see such option in visual studio,
it looks my visual studio add-in isn't working.
it says "You should refresh the code model" Woot? can someone explain me how to do that please.
here are some output warnings when building my project:
Warning 1 warning : No resources in 'C:\Users\Admin\documents\visual
studio
2010\Projects\VisualStudio\test\test.qrc'. C:\Users\Admin\documents\visual
studio 2010\Projects\VisualStudio\test\RCC Warning 2 warning LNK4099:
PDB 'vc100.pdb' was not found with 'qtmaind.lib(qtmain_win.obj)' or at
'C:\Users\Admin\documents\visual studio
2010\Projects\VisualStudio\vc100.pdb'; linking object as if no debug
info C:\Users\Admin\documents\visual studio
2010\Projects\VisualStudio\test\qtmaind.lib(qtmain_win.obj)
I'm going to explain a little bit how things work and the relationships between the files, and hopefully this will solve your problem.
When you edit the ui file using the designer all changes are made to the ui file itself. Then when you build a couple of things will happen.
First... a custom build step will be run on the ui file. This build step runs "uic" as Macke said, and will generate a file called "ui_thenameofyouruifile.h". Where this file is located depends on your project settings, but if you look in your project you should see a folder called Generated Files in your project.
If you look in there you should see the newly generated file. This is the code that is "changed" when you make changes to your form. Now if this file is not updated, or does not exist at all, then somehow your project settings got messed up. In this case I would remove your .ui file from the project and re-add it. The add-in should do it's magic and add all the stuff you need. Build again and it should work. (I assume that is probably your problem)
The second thing that should happen when you build, is that the class that uses your ui file should recompile. Generally when you create a ui file, you also create an accompanying .h and .cpp file. This is where we do any of the fun logic that we might need in our window. The Qt designer will never ever change this class.
In the header file we refer to the ui file by doing this:
namespace Ui {
class thenameofyouruifile;
}
#include "ui_thenameofyouruifile.h"
and then we add a member variable
Ui::thenameofyouruifile UI;
There are a couple of ways to do this, but basically that's the idea. The add-in is supposed to configure your project so that the directory where the generate files go is included in the "additional include directories" in your project settings, but that is another place to check to make sure that your code is really linking with the correct generated file.
If Qt Add-In installed properly, it should generate the custom build step for Qt related files (.ui or moc file). I have not tried Qt Add-in with VS 2010, but with VS 2008 it's okay.
The work-around for your problem, you need to add manually the custom build step for each ui file you have in the project. To do this, the step is:
Right clicked the ui file, and click the properties (I'm using VS-2008 to do this step, and expect this may not be much different in VS 2010).
Under custom build step, add this in the command line: "$(QTDIR)\bin\uic.exe" -o ".\GeneratedFiles\ui_$(InputName).h" "$(InputPath)"
And add this under output: ".\GeneratedFiles\ui_$(InputName).h"
And this under additional dependencies: $(QTDIR)\bin\uic.exe. Then click apply / ok.
If this is done, the ui file is compilable, (when you right click it, it can be compiled), so when the ui file content change, the new ui code (.h) file is regenerated.
Alternatively, to reset the VS project file (vcprojx) you can create Qt project in Qt creator, (or if you have already one), and then convert the Qt creator project (.pro) into vcproj using this command line:
qmake -spec win32-msvc2010 -tp vc
This will create the vcproj with the proper custom build step for you (in case you have many ui files, then you don't need to do the first approach).
If you've created a Qt widget using the new class wizard, stuff should work as expected.
I.e. your .ui files are compiled by Qt's uic to .cpp files, i.e. you need to build your project to get these changes into the ui-class.
So, the .ui files should be added to the project, and have some special build rules that invoke 'uic' on them. If that's not the case, try and re-add them to your project (that way, the Qt add-in should configure the build rules)
Normally, you have a class that inherits QWidget which then includes the compiled cpp-class, by one way or another, usually as a member variable (but inheritance is an option too).
Adding an .ui-file straight up should work too (if you're in a Qt project, which you are..), but obviously something is wrong.
Does the example projects work as expected?

How to add common/inc folder to a CUDA project at Visual Studio?

I want to develop gpu computing algorithms using CUDA. I'm using Visual Studio 2010 Ultimate edition. After I install all the computing tools and SDK with samples, I see under project types "NVIDIA->CUDA->CUDA 4.0 Runtime" choice to start a CUDA project.
The problem is that I can't include source files located at ProgramData/NVIDIA Corporation/NVIDIA GPU Computing SDK 4.0/Common/inc to work with samples, use header files under GL directory etc. I'm trying to include them using "Additional Include Directories". I'm adding the full path, but it doesn't work. Visual Studio doesn't see those files.
How can I use these files? What should I type in to get these files?
I compiled cutil project under common directory, it solved some error problems while trying to compile samples but it made no use for the issue I stated above.
These are the steps I took to install CUDA into VS2010.
Create a normal project of your choice. (e.g. win32)
Right click the project and choose Build Customizations. If you have installed the tools and SDK correctly you should see a CUDA 4.0 target. (If your project becomes corrupt you may also have to replace the existing ExtensionSetting import in your .vcxproj file)
<ImportGroup Label="ExtensionSettings">
<Import Project="$(VCTargetsPath)\BuildCustomizations\CUDA 4.0.props"/>
</ImportGroup>
Your include path should already be setup, if it is not then add $(CUDA_INC_PATH) to your VC++ include directory.
Add cudart.lib to your Linker additional libraries ensuring that $(CudaToolkitLibDir) is added to the paths.
Create a file and give it the .cu file extension. Right click the file, go to properties and select the Item Type as "Cuda C/C++".
Once sthis i complete you should be able to compile Cuda in VS2010. I may have forgetten some steps, you may need to fiddle abit, I will edit this post if I recall tomorrow.

Any addins for VS2010 to support VS2005 projects?

Some of the old projects in our company are left to be built with VS2005 in autobuild system (making them build correctly in 2010 cost time). Is it any addins for VS2010 that will allow to open VS2005 project and edit it's files without converting project file itself to VS2010 format (converting will kill autobuild)? Of course i can create a separate project named "xxx_vs2010.vcproj" for each of such products, but that will be a mess :(.
No.
An alternative to consider is to target the VS2005 C++ toolchain from within VS2010. See Native Multi-Targeting and the Project Upgrade Guide. That way, no need to modify source code to appease the VS2010 C++ compiler.

Resources