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
(Describe installing or building Qt 5)
 
(8 intermediate revisions by the same user not shown)
Line 6: Line 6:
=Qt Visual Studio Tools=
=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.
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 [https://code.qt.io/cgit/qt-labs/vstools.git/about/ README.md] file in the Qt Visual Studio Tools sources.


===Get the sources===
===Get the sources===
Line 28: Line 30:
or install a [https://download.qt.io/official_releases/qt/5.12/5.12.9/ pre-built binary package].
or install a [https://download.qt.io/official_releases/qt/5.12/5.12.9/ pre-built binary package].


===Build Qt from sources===
====Build Qt from sources====


See [[Building Qt 5 from Git]] for the prerequisites and steps to build Qt from sources.
See [[Building Qt 5 from Git]] for the prerequisites and steps to build Qt from sources.
Line 40: Line 42:
<code lang="bash">jom module-qtbase module-qtdeclarative</code>
<code lang="bash">jom module-qtbase module-qtdeclarative</code>


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


Visual Studio 2022 is a 64-bit application, whereas VS 2019 and 2017 are 32-bit applications. The
Visual Studio 2022 is a 64-bit application, whereas VS 2019 and 2017 are 32-bit applications. The
Line 51: Line 53:
===Build the Qt Visual Studio Tools===
===Build the Qt Visual Studio Tools===


Change the directory into 'src' and run 'qmake && make' (or 'mingw32-make', 'nmake' ...) to build
After cloning the repository, follow the instructions below to build the Qt Visual Studio Tools.
the Qt Visual Studio Tools command line applications. Once finished, open the solution QtVsTools.sln
 
in Visual Studio and build the solution.
====Requirements====
 
The following is required in order to build the Qt Visual Studio solution:
 
* 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.
 
====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===
===Build the Qt Visual Studio Tools documentation===


Run 'qmake && make docs' (or 'mingw32-make docs', 'nmake docs' ...) from the root directory to
Run one of the following commands (depending on your setup) from the root directory to build the Qt Visual Studio Tools documentation:
build the Qt Visual Studio Tools documentation. You need to have 'qdoc' and friends built already.
See the Qt documentation for the prerequisites and steps to build Qt documentation from sources.
https://wiki.qt.io/Building_Qt_Documentation
 
===How to debug the Qt Visual Studio Tools===


To debug the resulting VSIX, select the 'QtVsTools' node, right click and choose 'Properties|Debug'.
* qmake && jom docs
Update 'Start Action|Start external program:' to point to your Visual Studio 'devenv.exe' application.
* qmake && make docs
Update 'Start Options|Command line arguments:' with '/rootSuffix Exp'. Note: The implemented post
* mingw32-make docs
build targets will only work reliable if you use the 'Exp' hive of Visual Studio.
* nmake docs


===How to locally test the Qt Visual Studio Tools update===
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.


Inside the src\config directory, edit the qt.io.xml file and modify the following tags:
===Debug the Qt Visual Studio Tools===


    <updated>2016-11-11T10:51:55Z</updated>  Use the current date and time, keep the 'T' and 'Z'
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].
    <id>{ Product ID }</id>                  Set to the Product ID that can be found in the 'source.extension.vsixmanifest' file,
                                              for example: <id>QtVsTools.30112013-cd02-4fd0-89bd-e36f85abe16a</id>
    <Version>{ Version }</Version>            Set to the Version that can be found in the 'source.extension.vsixmanifest' file,
                                              for example: <Version>2.0.0</Version>


Copy the XML file and the VSIX package inside a new folder side by side and open the
To configure the solution for debugging:
'Tools | Options | Extensions and Updates' settings dialog in Visual Studio. Add a new entry in the
Additional Extension Gallery, like this:


    Name: qt.io
# In the solution explorer, right-click QtVsTools.Package > Set as startup
     Url: file://path/to/your/atom.xml
# 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