Qt wiki will be updated on October 12th 2023 starting at 11:30 AM (EEST) and the maintenance will last around 2-3 hours. During the maintenance the site will be unavailable.

Visual Studio Add-in: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
 
(36 intermediate revisions by 11 users not shown)
Line 1: Line 1:
'''English''' [[QtVSAddin_Russian|Русский]] "French":http://qt-devnet.developpez.com/tutoriels/add-in-visual-studio/compiler/
{{LangSwitch}}
[[Category:Tools]]


[[Category:Tools]]<br />[toc align_right="yes" depth="3"]
'''French translators see also:''' http://qt-devnet.developpez.com/tutoriels/add-in-visual-studio/compiler/


= Qt Visual Studio Add-in =
=Qt Visual Studio Tools=
The Qt Visual Studio Tools integrate the Qt development tools into Microsoft Visual Studio. This enables developers to use the standard Windows development environment without having to worry about Qt-related build steps or tools.


== Getting the source ==
For most up-to-date instructions, see the [https://code.qt.io/cgit/qt-labs/vstools.git/about/ README.md] file in the Qt Visual Studio Tools sources.


The source code of the add-in is hosted on gitorious at http://qt.gitorious.org/qt-labs/vstools
===Get the sources===


To create a repository clone, execute the following command:
Use Git to check out the Qt Visual Studio Tools sources that are hosted at: http://code.qt.io/cgit/qt-labs/vstools.git


<code>git clone git://gitorious.org/qt-labs/vstools.git<code>
To create a repository clone, execute one of the following commands:


== Instructions for Qt 5.x ==
<code lang="bash">git clone git://code.qt.io/qt-labs/vstools.git</code>


As the addin is a Qt app itself, make sure that you have the following software installed:
<code lang="bash">git clone https://code.qt.io/qt-labs/vstools.git</code>


* Visual Studio 2008+
==== Contribute changes ====
* Perl
* Qt 5.0+


p{font-size:larger}. '''''These instructions refer to Visual Studio 2012. Replace any references to VS2012 with the appropriate file for your VS version (2008, 2010 and 2012 supported).'''''
Contributions to the Qt Visual Studio Tools project must be submitted to the [https://codereview.qt-project.org/admin/repos/qt-labs/vstools qt-labs/vstools] Gerrit repository. For instructions on how to set up a Gerrit account and contribute to Qt projects, see [[Setting up Gerrit]].


=== Building the addin ===
===Install Qt===


Open a command shell with a Qt build environment (Visual Studio built-in prompt configured with Qt in appropriate environment variables, 32 or 64-bit) and cd into your add-in source directory.
To build the Qt Visual Studio Tools, an installation of Qt is required. The version of Qt that is
currently supported is 5.12.9. Either build Qt from the sources available in the
[https://code.qt.io/cgit/qt/qt5.git/tag/?h=v5.12.9 Qt Project Git Repository Browser]
or install a [https://download.qt.io/official_releases/qt/5.12/5.12.9/ pre-built binary package].


Execute the following commands:
====Build Qt from sources====


</code>cd Qt4VS2003<br />createUserFiles.bat<code>
See [[Building Qt 5 from Git]] for the prerequisites and steps to build Qt from sources.


This sets up reference paths and debug settings.
Recommended options for the configure tool:


</code>cd ..qmake<br />nmake<br />cd ..devenv qt5appwrapper2012.sln /useenv /Build release<br />cd ..<br />qmake -r<br />nmake<code>
<code lang="bash">configure -static -opensource -confirm-license -nomake examples -nomake tests -opengl desktop</code>
<br />This builds the external QRC editor which is launched from within Visual Studio.
<br />At this point, the addin can be built. Open Qt4VS2003\Qt5VSAddin2012.sln as an administrator (the build will fail if you don't), and build the entire solution.
<br />h3. Installation
<br />Open the Qt4VS2003\Qt4VSAddin folder, and copy Qt5VSAddin.AddIn and the Release directory to your VS Addins folder- by default this is "&amp;#37;USERPROFILE&amp;amp;#37;Studio 2012\Addins", but this can be changed under Tools->Options->Environment->Add-in Security. Rename Release to something meaningful (like Qt5VSAddin, since it goes with the addin).


Open Qt5VSAddin.AddIn in your favorite text editor, and find the Version tag. Change it to the version appropriate for your VS version - 2008 is 9.0, 2010 is 10.0, and 2012 is 11.0. Find the Assembly tag and change it to reflect the location of the Qt5VSAddin.dll file within the binary folder, i.e. Qt5VSAddin\Qt5VSAddin.dll.
Recommended options for [[Jom]]:


Go back to Visual Studio, and open Tools->Add-in Manager. Select the addin and restart VS. You should now have a QT5 menu, to the right of VIEW.
<code lang="bash">jom module-qtbase module-qtdeclarative</code>


=== Configuration ===
====32-bit or 64-bit====


You should probably configure the addin for your Qt installation. Open QT5->Qt options, and add any versions of Qt you have installed. The rest of the options should be fine for normal use.
Visual Studio 2022 is a 64-bit application, whereas VS 2019 and 2017 are 32-bit applications. The
target platform for which Qt is built must reflect this:


== Build Instructions for Qt 4.x ==
* For Visual Studio 2022, use Qt built for the x64 platform.
* For Visual Studio 2019, use Qt built for the x86 platform.
* For Visual Studio 2017, use Qt built for the x86 platform.


Make sure that you have the following software installed:
===Build the Qt Visual Studio Tools===


* Visual Studio 2005 or above
After cloning the repository, follow the instructions below to build the Qt Visual Studio Tools.
* Perl
* Qt 4.7.0 or newer


Open a command shell with a Qt build environment (Visual Studio build, 32 bit) and cd into your add-in source directory.
====Requirements====


Execute the following commands:
The following is required in order to build the Qt Visual Studio solution:


</code>cd Qt4VS2003<br />createUserFiles.cmd<code>
* Visual Studio 2017, 2019 or 2022, with the following workloads:
** Desktop development with C++
**.NET desktop development
**[https://docs.microsoft.com/en-us/visualstudio/extensibility/installing-the-visual-studio-sdk Visual Studio extension development]
* [https://devblogs.microsoft.com/cppblog/linux-development-with-c-in-visual-studio/ Linux development with C++]
* [https://github.com/microsoft/vswhere vswhere tool] (usually installed with Visual Studio):
** [https://github.com/microsoft/vswhere/releases/tag/2.7.1 Version 2.7.1] or greater.
* Git must be installed and included in the PATH environment variable.


This sets up reference paths and debug settings.
====Environment variables====


</code>cd ComWrappers\qmakewrapper<br />qmake<br />nmake<br />cd ..devenv qtappwrapper2008.sln /useenv /Build release<code>
Set environment variables in the format QTBUILD_STATIC_VS<version> according to the installed VS versions:
* QTBUILD_STATIC_VS2017 = <path to Qt installation built with msvc2017>
* QTBUILD_STATIC_VS2019 = <path to Qt installation built with msvc2019>
* QTBUILD_STATIC_VS2022` = <path to Qt installation built with msvc2022>


Adjust the number in qtappwrapper2008.sln according to the VS version you’re using.<br />Duplicates of the addin’s project files exist for every supported Visual Studio version.
For example, if Qt is installed in C:\build, the following environment variables must be set:


</code>cd ..<br />qmake -r<br />nmake<code>
    QTBUILD_STATIC_VS2019=C:\build\qt_5.12.9_msvc2019_x86
    QTBUILD_STATIC_VS2022=C:\build\qt_5.12.9_msvc2022_x64


This builds the external QRC editor which is launched from within Visual Studio.<br />Now we’re ready to open the main solution which contains the actual add-in.
====Initialization====


</code>start Qt4VS2003\Qt4VSAddin2008.sln</code>
In a command prompt (a "regular" one, not a VS Developer/Native Tools prompt), CD to the
root of the repository and run vstools.bat to initialize the solution and open it in Visual
Studio, with the following arguments:


Now you should be able to build the solution.<br />Before trying to run your freshly built add-in, read the next section.
    C:\...\vstools> vstools -init -startvs


== Running and Debugging ==
This will:
* Delete all output files
* Restore NuGet packages
* Run an initial text template generation
* Open the solution in the VS IDE, ready to build/debug


To run and debug the development version of the Qt Visual Studio Add-in we need to do a little<br />setup work once again. Note that you can have the Add-in’s release version installed.<br />You can switch between these two installations as you will see soon.
This procedure must be repeated when opening the solution on another version of VS. For example, assuming VS 2022 and VS 2019 are installed, to open the solution in VS 2019 after it has already been initialized and used in VS 2022, run the following:


=== Install the Add-in’s Description File ===
    C:\...\vstools> vstools -vs2019 -init -startvs


Open the directory where your personal Visual Studio settings are stored. This is usually<br />something like “USERPROFILE\Documents\Visual Studio 2008”.<br />We’ll just use that directory for illustration. Also, we’ll assume that the<br />add-in’s repository is located in c:.<br />Execute the following commands:
By default, if no VS version is specified, the most recent version is selected.


<code>cd "USERPROFILEStudio 2008"<br />md Addins<br />cd Addins<br />copy c:4VS2003\Qt4VSAddin\Qt4VSAddin.AddIn</code> .
====Target platform====


Qt4VSAddin.AddIn is the add-in’s description file and Visual Studio can now find it.<br />For other Visual Studio versions than 2008 you must adjust the Version tag in the<br />Qt4VSAddin.Addin file.
The solution platform must be set to 'x64' for VS 2022, and 'x86'
or 'Any CPU' for VS 2019 and VS 2017.


Your installed release version of the add-in is now turned off and cannot be loaded into<br />Visual Studio anymore. To restore the old state, rename the file extension of Qt4VSAddin.AddIn<br />to some bogus value like Qt4VSAddin.AddIn.foo. This ensures that it will be ignored by Visual<br />Studio and the original add-in will be loaded.
===Build the Qt Visual Studio Tools documentation===


=== Run the Add-in’s Development Version ===
Run one of the following commands (depending on your setup) from the root directory to build the Qt Visual Studio Tools documentation:


Now that the .Addin file is in place, we’re ready to try out the development version of the<br />add-in. Open the solution file (e.g. Qt4VSAddin2008.sln) and press F5.
* qmake && jom docs
* qmake && make docs
* mingw32-make docs
* nmake docs


Another instance of Visual Studio is started. We will call this instance VS2 and the Visual<br />Studio Instance where the add-in’s solution is loaded VS1.
You need to have qdoc and friends built already or run qmake from an installed Qt version.
See [[Building Qt Documentation]] for the prerequisites and steps to build Qt documentation from sources.


The add-in is not yet loaded in VS2. To load it, select “Tools/Add-in Manager…” click the<br />first checkbox in the “Qt4 Add-in Development Version” line and press OK.<br />Now you should have a “Qt” menu entry in the menubar of Visual Studio which means that the<br />add-in has been successfully loaded.
===Debug the Qt Visual Studio Tools===


In VS1 you can set breakpoints and do all the debugging you need. In VS2 you’re controlling
To debug the Qt Visual Studio tools extension, the QtVsTools.Package project must be set as the startup project. Also, the target binary for the debug session must be set to the Visual Studio executable (devenv.exe), with the option to start an [https://docs.microsoft.com/en-us/visualstudio/extensibility/the-experimental-instance experimental instance].
 
To configure the solution for debugging:
 
# In the solution explorer, right-click QtVsTools.Package > Set as startup
# In the solution explorer, right-click QtVsTools.Package > Properties
# In the properties dialog, select the Debug page
# In the debug properties page, set the following options:
    Start external program_ = path to the Visual Studio executable (devenv.exe)
    Command line arguments_ = /rootSuffix Exp

Latest revision as of 12:47, 7 December 2021

En Ar Bg De El Es Fa Fi Fr Hi Hu It Ja Kn Ko Ms Nl Pl Pt Ru Sq Th Tr Uk Zh

French translators see also: http://qt-devnet.developpez.com/tutoriels/add-in-visual-studio/compiler/

Qt Visual Studio Tools

The Qt Visual Studio Tools integrate the Qt development tools into Microsoft Visual Studio. This enables developers to use the standard Windows development environment without having to worry about Qt-related build steps or tools.

For most up-to-date instructions, see the README.md file in the Qt Visual Studio Tools sources.

Get the sources

Use Git to check out the Qt Visual Studio Tools sources that are hosted at: http://code.qt.io/cgit/qt-labs/vstools.git

To create a repository clone, execute one of the following commands:

git clone git://code.qt.io/qt-labs/vstools.git
git clone https://code.qt.io/qt-labs/vstools.git

Contribute changes

Contributions to the Qt Visual Studio Tools project must be submitted to the qt-labs/vstools Gerrit repository. For instructions on how to set up a Gerrit account and contribute to Qt projects, see Setting up Gerrit.

Install Qt

To build the Qt Visual Studio Tools, an installation of Qt is required. The version of Qt that is currently supported is 5.12.9. Either build Qt from the sources available in the Qt Project Git Repository Browser or install a pre-built binary package.

Build Qt from sources

See Building Qt 5 from Git for the prerequisites and steps to build Qt from sources.

Recommended options for the configure tool:

configure -static -opensource -confirm-license -nomake examples -nomake tests -opengl desktop

Recommended options for Jom:

jom module-qtbase module-qtdeclarative

32-bit or 64-bit

Visual Studio 2022 is a 64-bit application, whereas VS 2019 and 2017 are 32-bit applications. The target platform for which Qt is built must reflect this:

  • For Visual Studio 2022, use Qt built for the x64 platform.
  • For Visual Studio 2019, use Qt built for the x86 platform.
  • For Visual Studio 2017, use Qt built for the x86 platform.

Build the Qt Visual Studio Tools

After cloning the repository, follow the instructions below to build the Qt Visual Studio Tools.

Requirements

The following is required in order to build the Qt Visual Studio solution:

Environment variables

Set environment variables in the format QTBUILD_STATIC_VS<version> according to the installed VS versions:

  • QTBUILD_STATIC_VS2017 = <path to Qt installation built with msvc2017>
  • QTBUILD_STATIC_VS2019 = <path to Qt installation built with msvc2019>
  • QTBUILD_STATIC_VS2022` = <path to Qt installation built with msvc2022>

For example, if Qt is installed in C:\build, the following environment variables must be set:

   QTBUILD_STATIC_VS2019=C:\build\qt_5.12.9_msvc2019_x86
   QTBUILD_STATIC_VS2022=C:\build\qt_5.12.9_msvc2022_x64

Initialization

In a command prompt (a "regular" one, not a VS Developer/Native Tools prompt), CD to the root of the repository and run vstools.bat to initialize the solution and open it in Visual Studio, with the following arguments:

   C:\...\vstools> vstools -init -startvs

This will:

  • Delete all output files
  • Restore NuGet packages
  • Run an initial text template generation
  • Open the solution in the VS IDE, ready to build/debug

This procedure must be repeated when opening the solution on another version of VS. For example, assuming VS 2022 and VS 2019 are installed, to open the solution in VS 2019 after it has already been initialized and used in VS 2022, run the following:

   C:\...\vstools> vstools -vs2019 -init -startvs

By default, if no VS version is specified, the most recent version is selected.

Target platform

The solution platform must be set to 'x64' for VS 2022, and 'x86' or 'Any CPU' for VS 2019 and VS 2017.

Build the Qt Visual Studio Tools documentation

Run one of the following commands (depending on your setup) from the root directory to build the Qt Visual Studio Tools documentation:

  • qmake && jom docs
  • qmake && make docs
  • mingw32-make docs
  • nmake docs

You need to have qdoc and friends built already or run qmake from an installed Qt version. See Building Qt Documentation for the prerequisites and steps to build Qt documentation from sources.

Debug the Qt Visual Studio Tools

To debug the Qt Visual Studio tools extension, the QtVsTools.Package project must be set as the startup project. Also, the target binary for the debug session must be set to the Visual Studio executable (devenv.exe), with the option to start an experimental instance.

To configure the solution for debugging:

  1. In the solution explorer, right-click QtVsTools.Package > Set as startup
  2. In the solution explorer, right-click QtVsTools.Package > Properties
  3. In the properties dialog, select the Debug page
  4. In the debug properties page, set the following options:
   Start external program_ = path to the Visual Studio executable (devenv.exe)
   Command line arguments_ = /rootSuffix Exp