pBook‎ > ‎

QT

VS 2010

posted Sep 21, 2014, 8:15 AM by Javad Taghia   [ updated Sep 21, 2014, 8:15 AM ]

Overview

You can develop Qt applications on Windows using the Microsoft Visual Studio IDE.

Qt provides precompiled binaries for use with Visual Studio and a plug-in that
integrates the Qt tools into the IDE.

The free Express Edition of Visual Studio does not support third-party plugins.
You must use a commercial version of Visual Studio to use the Qt plug-in.

We have only tested Visual Studio 2010.

This document assumes you have already installed Visual Studio with C++ tools.

Downloads

qt-win-opensource-4.8.1-vs2010.exe from http://qt.nokia.com/downloads/windows-cpp-vs2010

qt-vs-addin-1.1.10.exe from http://qt.nokia.com/downloads/visual-studio-add-in

Install Qt

Run qt-win-opensource-4.8.1-vs2010.exe and do a default install.

Add the QTDIR Environment Variable

Qt will install into C:\Qt\4.8.1

Create the following environment variable in the User variables environment

QTDIR=C:\Qt\4.8.1

Add %QTDIR%\bin to the PATH

Access the ‘Environment Variables’ dialog this way


Control Panel
-- System and Security
---- System
------ Advanced system settings
-------- Environment Variables

Add the new values to the ‘User variables’ section. You may have to add a PATH entry to the ‘User variables’ section also. This ‘User’ section PATH will get appended to the ‘System’PATH.

and SYSTEM VARIABLES on path add at the end c:Qt\4.8.1

Qt-Plugin for VS2010

Run the executable qt-vs-addin-1.1.10.exe and do a default install.

The next time you run VS2010 you should see a new Qt menu in the main menu bar.

 

VS 2012

posted Sep 21, 2014, 8:13 AM by Javad Taghia   [ updated Sep 21, 2014, 8:25 AM ]

VISUAL STUDIO 2012 ADD-IN FOR QT5

We need to download the following two:


       

  • Qt5 SDK , In my case, it's the Qt 5.1.1 for Windows 64-bit (VS 2012, OpenGL, 522 MB) (Info) 
  • https://download.qt-project.org/archive/qt/5.1/5.1.1/
  • Visual Studio Add-in 1.2.2 for Qt5 
  • http://download.qt-project.org/official_releases/vsaddin/




Once the Add-in installed successfully, we should now see QT5 show up on the Menu Bar:

Qt5inVS.png 



SETTING QT5 OPTIONS

The next step is to let the VS know where to get bin/qmake and lib/libraries. Without this step, we may get "Unable to find a Qt build! To solve this problem specify a Qt build" when we try to create a new Qt5 project.

In my case, they are under "C:\Qt\Qt5.1.1\5.1.1\msvc2012_64_opengl".

QtPath_to_qmake.png 

So, we need to pass this information.

From the top menu, QT5->Qt Options. Then, select "Add" and type the path into "Path"

AddNewQtVersion.png 

The "Version name" should be filled with 5.1.1. Hit OK.

Qt_Options.png 



CREATING A NEW QT5 PROJECT

Now, let's create a new Visual Studio Project: File -> New -> Project. We will now see a new addition called Qt5 Projects. This allows us to create various Qt applications. For now, select "Qt Application"

NewProject.png 

WelcomQt5GUI.png 

ProjectSettings.png 

We just leave everything untouched.

GeneratedClass.png 

Press "Finish"

SolutionExplorer.png 



BUILDING QT5 PROJECT

Let's build the project and run.

We're going to add simple UI (QProgressBar and QSlider) with "valueChanged(int)" signal and "setValue(int)" slot.

Before we start building the project, we may want to make sure that our host and target are set properly.

Things to check - in my case, Host:x64, Target (Platform):x64

If this is not set properly, we may get "linking problem: fatal error LNK1112: module machine type 'x64' conflicts with target machine type 'X86' or something similar error messages.

  • Check properties options in linker settings at: Properties > Configuration Properties > Linker > Advanced > Target Machine. In my case, it should be x64.
  • Select Build > Configuration Manager from the main menu in visual studio. Make sure our project has the correct platform specified.

After that, we should check Qt Project Settings as well. If this hasn't been set, we may get "There's no Qt version assigned to this project for platform x64" - visual studio plugin for Qt:

Right click the project > Qt Peoject Settings > Under the Properties tab > Version

QtProjectSettings_5_1_1.png 

Set signal and slot for the UI we added:

Signal_Slot_valueChanged_setValue.png 

Build and run:

HelloQtRun.png 

The progress bar keeps updated as we move the slider. So, seems to be working fine!

1-2 of 2