25

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.

Morten Fjeldstad
  • 903
  • 2
  • 10
  • 16
  • I'm also looking for the same solution. – sivabudh Feb 11 '10 at 23:32
  • 1
    @Morten, I just submitted a feature request to Nokia (I have standard support). I will post updates here when I got answers from them. – sivabudh Feb 12 '10 at 00:04
  • just a suggestion: you might want to change the title of this post to something like: "How to convert a regular VC++ vcproj project file to a Qt project?" my 2 cents. – sivabudh Feb 17 '10 at 17:16

5 Answers5

30

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:

  1. Right click on your project in "Solution Explorer", click on "Unload Project"
  2. Right click on your project in "Solution Explorer", click on "Edit .vcxproj"
  3. Add line <Keyword>Qt4VSv1.0</Keyword> between the tags <PropertyGroup Label="Globals"> and </PropertyGroup>.
  4. Right click on your project in "Solution Explorer", click on "Reload Project"
  5. 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.

Community
  • 1
  • 1
Jade
  • 3,156
  • 1
  • 34
  • 44
  • 1
    Thanks for that. I looked everywhere, and this is the only comment telling how to really do it. Except that after I did what you said, I had to remove all the cpp/h files from the project and re-add them. After doing that, it created the Generated Files folder with moc files. Thanks. – bmahf Dec 18 '14 at 17:38
  • @bmahf glad to know that it worked for you. Regarding the generation of moc files did you try the [answer](http://stackoverflow.com/a/6642863/262789) linked in the last paragraph of my answer. It contains instructions on triggering generation of the moc_* files. – Jade Jan 01 '15 at 15:25
  • Thanks! Saved my day! – nabroyan Oct 14 '15 at 14:04
  • 1
    Just a side note for 2. in the list: if you have a tag under already, then exchange that with the Qt4VSv1.0. – Silex Nov 16 '15 at 22:16
  • 1
    you saved 4 hours for me. Thank you – Pie_Jesu Apr 13 '16 at 08:36
9

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! =)

MBach
  • 1,647
  • 16
  • 30
sivabudh
  • 31,807
  • 63
  • 162
  • 228
  • 2
    There is a solution to this now, the workaround mention in a [comment](https://bugreports.qt-project.org/browse/QTVSADDINBUG-27?focusedCommentId=165769&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-165769) in the bug report or see my answer below. – Jade Jul 18 '12 at 03:05
4

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.

Community
  • 1
  • 1
Filip Bártek
  • 646
  • 7
  • 15
1

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

MBach
  • 1,647
  • 16
  • 30
sivabudh
  • 31,807
  • 63
  • 162
  • 228
1

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:

  1. A Qt project has a Keyword="Qt4VS1.0" immediately before TargetFrameWorkVersion line near the top of the file.
  2. At the bottom of the file you need to add the required Globals (in particular QtVersion.Win32)
  3. 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
  4. 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.

Hans Olsson
  • 54,199
  • 15
  • 94
  • 116