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
 
(29 intermediate revisions by 9 users not shown)
Line 1: Line 1:
{{Cleanup | reason=Auto-imported from ExpressionEngine.}}
{{LangSwitch}}
 
'''English''' [[QtVSAddin_Russian|Русский]] [http://qt-devnet.developpez.com/tutoriels/add-in-visual-studio/compiler/ French]
 
[[Category:Tools]]
[[Category:Tools]]


'''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 ==
 
The source code of the add-in is hosted on gitorious at http://qt.gitorious.org/qt-labs/vstools


To create a repository clone, execute the following command:
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.


<code>git clone git://gitorious.org/qt-labs/vstools.git</code>
===Get the sources===


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


As the addin is a Qt app itself, make sure that you have the following software installed:
To create a repository clone, execute one of the following commands:


* Visual Studio 2008+
<code lang="bash">git clone git://code.qt.io/qt-labs/vstools.git</code>
* Perl
* Qt 5.0+


'''''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).'''''
<code lang="bash">git clone https://code.qt.io/qt-labs/vstools.git</code>


=== Building the addin ===
==== Contribute changes ====


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.
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]].


Execute the following commands:
===Install Qt===


<code>cd Qt4VS2003
To build the Qt Visual Studio Tools, an installation of Qt is required. The version of Qt that is
createUserFiles.bat</code>
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].


This sets up reference paths and debug settings.
====Build Qt from sources====


<code>cd ..qmake
See [[Building Qt 5 from Git]] for the prerequisites and steps to build Qt from sources.
nmake
cd ..devenv qt5appwrapper2012.sln /useenv /Build release
cd ..
qmake -r
nmake</code>


This builds the external QRC editor which is launched from within Visual Studio.
Recommended options for the configure tool:


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.
<code lang="bash">configure -static -opensource -confirm-license -nomake examples -nomake tests -opengl desktop</code>


=== Installation ===
Recommended options for [[Jom]]:


Open the Qt4VS2003\Qt4VSAddin folder, and copy Qt5VSAddin.AddIn and the Release directory to your VS Addins folder- by default this is "%USERPROFILE%\Documents\Visual 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).
<code lang="bash">jom module-qtbase module-qtdeclarative</code>


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.
====32-bit or 64-bit====


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.
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:


=== Configuration ===
* 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.


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.
===Build the Qt Visual Studio Tools===


== Build Instructions for Qt 4.x ==
After cloning the repository, follow the instructions below to build the Qt Visual Studio Tools.


Make sure that you have the following software installed:
====Requirements====


* Visual Studio 2005 or above
The following is required in order to build the Qt Visual Studio solution:
* 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.
* 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.


Execute the following commands:
====Environment variables====


<code>cd Qt4VS2003
Set environment variables in the format QTBUILD_STATIC_VS<version> according to the installed VS versions:
createUserFiles.cmd</code>
* 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>


This sets up reference paths and debug settings.
For example, if Qt is installed in C:\build, the following environment variables must be set:


<code>cd ComWrappers\qmakewrapper
    QTBUILD_STATIC_VS2019=C:\build\qt_5.12.9_msvc2019_x86
qmake
    QTBUILD_STATIC_VS2022=C:\build\qt_5.12.9_msvc2022_x64
nmake
cd ..devenv qtappwrapper2008.sln /useenv /Build release</code>


Adjust the number in qtappwrapper2008.sln according to the VS version you’re using.
====Initialization====
Duplicates of the addin’s project files exist for every supported Visual Studio version.


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


This builds the external QRC editor which is launched from within Visual Studio.
    C:\...\vstools> vstools -init -startvs
Now we’re ready to open the main solution which contains the actual add-in.


<code>start Qt4VS2003\Qt4VSAddin2008.sln</code>
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


Now you should be able to build the solution.
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:
Before trying to run your freshly built add-in, read the next section.


== Running and Debugging ==
    C:\...\vstools> vstools -vs2019 -init -startvs


To run and debug the development version of the Qt Visual Studio Add-in we need to do a little
By default, if no VS version is specified, the most recent version is selected.
setup work once again. Note that you can have the Add-in’s release version installed.
You can switch between these two installations as you will see soon.


=== Install the Add-in’s Description File ===
====Target platform====


Open the directory where your personal Visual Studio settings are stored. This is usually
The solution platform must be set to 'x64' for VS 2022, and 'x86'
something like “USERPROFILE\Documents\Visual Studio 2008”.
or 'Any CPU' for VS 2019 and VS 2017.
We’ll just use that directory for illustration. Also, we’ll assume that the
add-in’s repository is located in c:.
Execute the following commands:


<code>cd "USERPROFILEStudio 2008"
===Build the Qt Visual Studio Tools documentation===
md Addins
cd Addins
copy c:4VS2003\Qt4VSAddin\Qt4VSAddin.AddIn</code> .


Qt4VSAddin.AddIn is the add-in’s description file and Visual Studio can now find it.
Run one of the following commands (depending on your setup) from the root directory to build the Qt Visual Studio Tools documentation:
For other Visual Studio versions than 2008 you must adjust the Version tag in the
Qt4VSAddin.Addin file.


Your installed release version of the add-in is now turned off and cannot be loaded into
* qmake && jom docs
Visual Studio anymore. To restore the old state, rename the file extension of Qt4VSAddin.AddIn
* qmake && make docs
to some bogus value like Qt4VSAddin.AddIn.foo. This ensures that it will be ignored by Visual
* mingw32-make docs
Studio and the original add-in will be loaded.
* nmake docs


=== Run the Add-in’s Development Version ===
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.


Now that the .Addin file is in place, we’re ready to try out the development version of the
===Debug the Qt Visual Studio Tools===
add-in. Open the solution file (e.g. Qt4VSAddin2008.sln) and press F5.


Another instance of Visual Studio is started. We will call this instance VS2 and the Visual
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].
Studio Instance where the add-in’s solution is loaded VS1.


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


In VS1 you can set breakpoints and do all the debugging you need. In VS2 you’re controlling the add-in.
# 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