Add Qt to existing Visual Studio project

(including some example)

“C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off” (Bjarne Stroustrup)

Firstly i wanna to explain about Qt “What is Qt ?” why I use Qt for create GUI? I know that is the first question that everyone want to know :) Okay let’s go!

#What is Qt?

(You can find more information about Qt from this URL: https://www.qt.io/)

Qt is much more than just a cross-platform SDK-it’s a technology strategy that lets you quickly and cost-effectively design, develop, deploy, and maintain software while delivering a seamless user experience across all devices. Easily create connected devices, UIs and applications with native C++ performance, Write your source code once, build and watch it run on any operating system and hardware. It’s truly cross-platform, Embrace the complete freedom to design tomorrow’s UIs. Use drag-and-drop tools, declarative QML or imperative C++ — the choice is yours, You can design your UI, write your code and much more in one cross-platform IDE. (https://www.qt.io/)

#Step 1: If you already install Visual Studio than just go to this URL https://www.qt.io/download

Download the open source version of Qt(Latest version is 5.10.1) that is suitable for your operating system. this will be automatically detected.

#Step 2: Start the installation. When asked for username, you have the option to skip that step and make sure you install the prebuilt components for the compiler you are using (MSVC2017/ MSVC2015), sources, charts and data visualization component and debugger support like this:

Now you have scroll down and select Tools, Qt Source, Qt chart and also Qt Data Visualization.

#Step 3 : Download and install the Qt Visual Studio Tools from : https://marketplace.visualstudio.com/items?itemName=TheQtCompany.QtVisualStudioTools-19123

#Step 4:

Open Visual studio, if the Qt VS Tools were correctly installed, you should find a new menu item “Qt VS Tools”.

#Step 5:

Add the path towards the components for the compiler: Qt VS Tools -> Qt Options-> Add button, Use the folder where you installed Qt

#Step 6:

Done! Restart Visual Studio and than let’s see how to create a new Qt project.

Creating A new Qt Project With VS STUDIO 2017

  1. From the VS menu, select “File” -> “New” -> “Project”.
  2. In the left-hand column of the “New Project” window, under “Visual C++” select “Qt”. In the middle column, select “Qt GUI Application”. Add a name and a location and then press “OK”.
You can save your application in any folders you want (Location)

3. In the following dialogs, keep the default settings (Next -> Next -> Finish).

4. In the “Source Files”, a file “main.cpp” should already be created (other .cpp, .h and .ui files will also be created).

5. Run the application. You should see an empty window:

Now! It’s Done for create a Qt Project. :) See you Next Blog! (How to build GUI Using C++ with Qt Platform)

Reference : https://www.qt.io/

April 14th, 2017

Qt framework is an ever growing cross-platform C++ framework, ideal for building desktop, mobile, and even embedded solutions. While you can use CMake to target Qt (if you do, you should read more about the Visual Studio support for CMake), Qt also provides its own Qt-optimized build system called qmake.

If your project is using qmake, this article covers the high-level steps to follow to import your projects into Visual Studio. You can read about other C++ project types in the guide for Bringing your C++ code to Visual Studio.

Add Qt to existing Visual Studio project

Step 1. Install the QT Visual Studio Extension. From the Marketplace, install the Qt Visual Studio Tools extension.

Step 2. Import your .pro projects into Visual Studio. To do that, select the Qt VS Tools > Open Qt Project File (.pro) to let the extension create a VS solution and project from your existing Qt .pro file. More information on this is available in the Qt docs covering Qt project management in Visual Studio.

What’s next

If you’re new to Visual Studio, learn more by reading the Getting Started with Visual Studio for C and C++ Developers topic and the rest of the posts in this Getting Started series aimed at C++ users that are new to Visual Studio. Download Visual Studio 2017 today, try it out and share your feedback.

Introduction​

The Visual Studio Code Extension for Torizon can be used to build, debug and deploy C and C++ applications.
This, of course, includes also applications using the Qt libraries. On the other side, Qt provides not just C++ libraries but also a rich set of tools to design user interfaces using widgets or QML language and specific build tools, as qmake, that use an ad-hoc project format.

To orchestrate those tools, Qt provides a fully integrated IDE named QtCreator and, at the moment, it is not fully integrated with Torizon. To overcome that we make it easier for you to use Visual Studio Code to work on the code and leverage Qt's design tools to design user interfaces. See a comparison below between development on Torizon and other platforms as Boot to Qt and Yocto:

Design WorkflowDevelopment Workflow
Torizon Qt Design Studio
✔ Enhanced UI design
Visual Studio Code
✔ Write Code
✔ Build and debug
✘ UI design
Boot to Qt / Yocto Qt Design Studio
✔ Enhanced UI design
Qt Creator
✔ Write Code
✔ Build and debug
✔ UI design

Be aware that you can use Qt IDEs (Qt Design Studio and Qt Creator) together with VS Code.

If you are looking to using Python with Qt, refer to the article How to build a GUI with Qt for Python and TorizonCore.

This article complies to the Typographic Conventions for Torizon Documentation.

Prerequisites​

  • Read the article Visual Studio Code Extension for Torizon and install the extension.
  • Install Qt Design Studio on your PC.
    • When using the Qt Maintenance Tool or installing development tools from the Qt website, it's possible to select the "Qt Design Studio" component. This installs components for both the widgets-base UI files and the QtQuick/QML ones.
  • Install the Remote Containers extension.
  • (optional) Go through the article How to do C/C++ Development on Torizon.
  • (optional) Read Qt Debian Container for Torizon to learn more about the Qt containers offered by Toradex. You don't need to focus on the practical instructions, they are abstracted by the Visual Studio Code Extension for Torizon.

Create a New Qt5 Project​

The video below illustrates the process of creating and deploying to a module a Qt project using the Visual Studio Code Extension for Torizon.

To create a new project you should:

  • Press F1 to open the command bar
  • Select Torizon C/C++: Create C/C++ application
  • Set the name of your new application and choose the folder where it will be created

Add Qt to existing Visual Studio project

  • Choose one of the Qt-based templates, three templates are provided:

    • Qt Core Sample: for console applications not using any UI or generating UI elements from code
    • Qt Widgets Sample: for graphical applications that use QtWidgets
    • Qt QML Sample: for applications using QtQuick/QML-based UI

Add Qt to existing Visual Studio project

Import an Existing Qt5 Project​

There is a generic article on How to Import a C/C++ Application to Torizon, and in addition to the tips below, it is highly recommended that you read it.

To import an existing project you will have to:

  • Press F1 to open the command bar
  • Select Torizon C/C++: Import existing application"
  • Navigate to the folder where the ".pro" file is stored
  • Select the right template, depending on the kind of UI implemented by the application

Add Qt to existing Visual Studio project

You can also read the blog post from May, 2021 Importing a Qt Project Into Torizon Using VS Code.

Considerations When Migrating Your Project to Torizon​

Existing projects may need to be modified to work on Torizon. Some points you need to consider:

  • The extension works on a single folder, if you have multiple ".pro" files you should group them together and use a project with SUBDIRS on the top level to build them in the right order.
  • After the build, binaries and data files should be deployed to a folder that is synchronized with the target, this can be done by adding: DESTDIR = $$(QMAKE_DESTIDIR) directive to the project file.
  • Torizon UI implementation is based on Wayland. Qt does a very good job wrapping platform-specific aspects, but you may experience some differences in the aspect of some UI elements or the way they are rendered on screen in terms of speed or other effects.

Edit QML Files on Qt Design Studio​

To open a QML file you can right-click on the file in the explorer bar or on the file itself when it is open in the VS Code editor, and select Open QML file in Qt Design Studio. This will start an instance of Qt Design Studio ready to edit your file.

Learn more about how to use Qt Design Studio in the official documentation.

Edit UI Files on Qt Design Studio​

To open a UI file you can right-click on the file in the explorer bar or on the file itself when it is open in the VS Code editor, and select Open UI file in QtDesigner. This will start an instance of QtDesigner ready to edit your file.

User interface definition files are processed during build time. This processing generates header files that can then be used to reference the UI elements.
When you finish editing your UI file, you must run the build command - Ctrl + Shift + B in Visual Studio Code - to ensure that changes you made in the user interface layout are reflected in the generated header files.

Learn more about how to use Qt Design Studio in the official documentation.

Qt Integration "Under the Hood"​

Qt integration uses Qt5 packages provided by Debian and licensed using the Qt open source license.

Version of the Qt Framework​

As the Debian Containers for Torizon are based on Debian, the Qt version used in our containers will be the same version provided by Debian at a given point in time.

Search for Qt packages in the Debian Packages search to get the exact version.

How to Add Qt Packages to a Project​

The provided templates include only a minimal subset of Qt feature's, those features have been split by Debian into multiple packages, to reduce the overall footprint of Qt and allow users to install only the features they actually need.
If a component required by your application is not found at build time or at runtime you can check packages built from Qt source code and add them to devpackages (build time) or extrapackages (runtime) configuration parameters.

  • Qt base packages
  • Qt 3d
  • Qt charts
  • Qt connectivity (bluetooth/NFC)
  • Qt declarative (QtQuick/QML)
  • Qt graphical effects (for QML)
  • Qt image formats (TGA, TIFF, and others)
  • Qt location
  • Qt multimedia (Widgets and QML)
  • QtQuick controls
  • QtQuick controls 2
  • Qt script
  • Qt sensors
  • Qt serial port
  • Qt speech
  • Qt SVG support
  • Qt virtual keyboard
  • Qt web engine
  • Qt web kit
  • Qt web channel
  • Qt web view
  • Qt web sockets
  • Qt XML patterns

Notice that for many of the components you have:

  • A runtime component (usually named libqt5*) that must be added to extrapackages
  • A development component (named in the same way with "-dev" suffix)that must be added to devpackages since it provides headers and libraries used at build time.

Webinars and Videos​

This section has on-demand webinars and videos to help you through development.

Importing a Qt Project Into Torizon Using VS Code​

How to add Qt to Visual Studio 2022?

Installation packages are available for download at the VS Marketplace or directly in the VS 2022 IDE: select Extensions > Manage Extensions from the IDE menu, and then search for "qt".

Can you open Qt Project in Visual Studio?

pro projects into Visual Studio. To do that, select the Qt VS Tools > Open Qt Project File (. pro) to let the extension create a VS solution and project from your existing Qt . pro file.

How to create Qt project in Visual Studio?

From the VS menu, select “File” -> “New” -> “Project”. In the left-hand column of the “New Project” window, under “Visual C++” select “Qt”. In the middle column, select “Qt GUI Application”. Add a name and a location and then press “OK”.

Does Visual Studio support Qt?

You can install and update Qt VS Tools directly from Microsoft Visual Studio.