How to put Qt 5.7 with MSVC2015 to work?

2

I have Microsoft Visual Studio Community 2015 for some time.

I installed Qt 5.7 via online installer and included msvc2015 (already checked) in the installation program list. I tried to use Qt Creator, but it gives a compilation error.

The compilation message is as follows.

10:48:14: Running steps for project BinaryConverter...
10:48:14: Configuration unchanged, skipping qmake step.
10:48:15: Starting: "C:\Qt\Tools\QtCreator\bin\jom.exe" 
    C:\Qt\Tools\QtCreator\bin\jom.exe -f Makefile.Debug
    cl -c -nologo -Zc:wchar_t -FS -Zc:strictStrings -Zc:throwingNew -Zi -MDd -GR -W3 -w34100 -w34189 -w44996 -w44456 -w44457 -w44458 -wd4577 -wd4467 -EHsc /Fddebug\BinaryConverter.vc.pdb -DUNICODE -DWIN32 -DWIN64 -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I..\BinaryConverter -I. -IC:\Qt.8\msvc2015_64\include -IC:\Qt.8\msvc2015_64\include\QtWidgets -IC:\Qt.8\msvc2015_64\include\QtGui -IC:\Qt.8\msvc2015_64\include\QtANGLE -IC:\Qt.8\msvc2015_64\include\QtCore -Idebug -I. -IC:\Qt.8\msvc2015_64\mkspecs\win32-msvc2015 -Fodebug\ @C:\Users\RHERWOLF\AppData\Local\Temp\main.obj.3708.47.jom
'cl' nÆo ‚ reconhecido como um comando interno
ou externo, um programa oper vel ou um arquivo em lotes.
jom: E:\Dropbox\Projetos\Qt Creator Projects\build-BinaryConverter-Desktop_Qt_5_8_0_MSVC2015_64bit-Debug\Makefile.Debug [debug\main.obj] Error 1
    cl -c -nologo -Zc:wchar_t -FS -Zc:strictStrings -Zc:throwingNew -Zi -MDd -GR -W3 -w34100 -w34189 -w44996 -w44456 -w44457 -w44458 -wd4577 -wd4467 -EHsc /Fddebug\BinaryConverter.vc.pdb -DUNICODE -DWIN32 -DWIN64 -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I..\BinaryConverter -I. -IC:\Qt.8\msvc2015_64\include -IC:\Qt.8\msvc2015_64\include\QtWidgets -IC:\Qt.8\msvc2015_64\include\QtGui -IC:\Qt.8\msvc2015_64\include\QtANGLE -IC:\Qt.8\msvc2015_64\include\QtCore -Idebug -I. -IC:\Qt.8\msvc2015_64\mkspecs\win32-msvc2015 -Fodebug\ @C:\Users\RHERWOLF\AppData\Local\Temp\unwin.obj.3708.546.jom
'cl' nÆo ‚ reconhecido como um comando interno
ou externo, um programa oper vel ou um arquivo em lotes.
jom: E:\Dropbox\Projetos\Qt Creator Projects\build-BinaryConverter-Desktop_Qt_5_8_0_MSVC2015_64bit-Debug\Makefile.Debug [debug\unwin.obj] Error 1
jom: E:\Dropbox\Projetos\Qt Creator Projects\build-BinaryConverter-Desktop_Qt_5_8_0_MSVC2015_64bit-Debug\Makefile [debug] Error 2
10:48:19: The process "C:\Qt\Tools\QtCreator\bin\jom.exe" exited with code 2.
Error while building/deploying project BinaryConverter (kit: Desktop Qt 5.8.0 MSVC2015_64bit)
The kit Desktop Qt 5.8.0 MSVC2015_64bit has configuration issues which might be the root cause for this problem.
When executing step "Make"
10:48:19: Elapsed time: 00:04.

Then I downloaded the site and installed "Qt VS Tools MSVC 2015". Appearing in Visual Studio the option to create Qt GUI project ...

...butwhentryingtocreateaprojecttheerrorbelowoccurs.

What do I do to finally use Qt?

    
asked by anonymous 18.01.2017 / 13:57

2 answers

2

Your error with QtCreator is probably some wrong configuration even (as indicated by the error message). If I'm going to use it, I suggest trying to re-create the VS 2015 Kit ( follow the Qt Creator documentation ) .

About the VS Toolkit, I do not know how to help. I never liked this tool because it is difficult to understand and use and almost always gives some problem. Apart from that it has serious difficulties of updating between the versions of Visual Studio. This video can be useful (I do not know if it's up to date) and maybe another colleague who works with Qt (the @ GuilhermeNascimento most likely! Rs) can help you with this.

But you can generate the Visual Studio files directly from the project file (.pro file) by using qmake . And the advantage of using qmake is that you gain portability: you can generate VS project files in Windows or makefiles in Linux, for example.

I used to use this script (with .cmd extension) that worked on both Windows (as batch script) and Linux (as a bash script):

:;#
:;# This is a combined Batch (Windows) + Bash (Linux) command file that:
:;# - (re)creates the Visual Studio project files (if ran on Windows)
:;# - (re)creates the project Makefile (if ran on Linux)
:;#
:;# The syntax used to create the combined Batch-Bash commands comes from this
:;# answer in StackOverflow: https://stackoverflow.com/a/17623721/2896619
:;#
:;# The .cmd extension was used just to make it less weird when used on Linux! :)
:;#
:;# Author: Luiz C. Vieira
:;# Version: 1.0
:;#

:; qmake -o Makefile core.pro; exit
@echo off
qmake -spec win32-msvc2012 -tp vc

It uses a cool "trick" (described in this SOen response ) to run on both Windows and Linux .

But in the last few years I've changed all this by using CMake . Aside from being a fantastic free tool, it makes it much easier to work when you want portability, and many of the open source projects out there use it (which also makes it easier to integrate when these projects are used). It has a small learning curve, of course, but it's worth the time. With CMake I do not even have to worry about the directories where dependencies meet, and it is able to generate and maintain the Visual Studio 2015 project files (and you never need to warm up with the VS Toolkit!).

Here is an example of a CMakeLists.txt file (which is at the root of your project, which contains your CMake configuration):

# Versão mínima do CMake esperada
cmake_minimum_required(VERSION 3.1.0)

# Nome do projeto
project(teste)

# Define as configurações de compilação disponíveis no projeto (debug, release, etc)
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
  set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
  set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
    "MinSizeRel" "RelWithDebInfo")
endif()

# Configuração do Qt5
set(CMAKE_AUTOMOC ON) # Automaticamente faz o MOC das classes QObject
set(CMAKE_AUTORCC ON) # Automaticamente compila os arquivos de recurso
set(CMAKE_AUTOUIC ON) # Automaticamente gera os metadados das interfaces gráficas
find_package(Qt5 REQUIRED Core Gui Widgets) # Encontra o Qt e adiciona os pacotes desejados

# Configura o código-fonte do seu projeto
# (nesse caso, se encontra na subpasta './src/')
file(GLOB SRC src/*.cpp src/*.h)

# Cria o projeto do executável, apontando para o código-fonte
# No Windows usa 'WIN32' para indicar que é uma aplicação gráfica
# (caso contrário, seria somente uma aplicação "console")
if(WIN32)
    add_executable(teste WIN32 ${SRC})
else()
    add_executable(teste ${SRC})
endif()

# Linka o projeto com as bibliotecas do Qt
target_link_libraries(teste Qt5::Core Qt5::Gui Qt5::Widgets)

# No caso do Qt os includes são feitos automaticamente pelo 'find_package',
# mas em outras bibliotecas você pode precisar incluir também algo do tipo:
#
# 'include_directories(${VAR})'
#
# onde VAR é uma variável com todos os paths de includes.
#
# As bibliotecas costumam indicar em sua documentação o nome da variável que
# fornecem justamente para esse propósito. Por exemplo, ao se usar OpenCV:
#
# 'find_package(OpenCV REQUIRED core highgui imgproc)'
# 'include_directories(${OpenCV_INCLUDE_DIRS})'
#

In order to use it, simply open CMake, set the project directory (where CMakeLists.txt is) and build (where the VS project will be generated, and where the compiled files will be produced when you work inside VS, this can be any path, and you can erase it and generate it again if you need it - so keep it separate.)

In my example I have the following structure in the project root:

c:\temp\SOPT\
    .\CMakeLists.txt
    .\src\main.cpp

And, for convenience, I generated the binaries in:

c:\temp\SOPT\build\
    .\teste.sln
    .\teste.vcxproj
    etc

(Note that the c:\temp\SOPT\build\ folder is generated, and can be deleted without problem because it does not contain the fonts.)

After opening CMake I defined the directories and clicked on "Configure". It will (1) ask if you create the build directory and (2) ask to select the compiler. Visual Studio 2015 has the "14" version (because of Microsoft's idiosyncrasies). Also remember to choose the version between 32 or 64 bits depending on your Qt installation. After confirming it will read the configuration and prepare the project:

Nowjustclickon"Generate" that the project will be generated (or updated, if you made any changes in a project already generated). The "Open Project" button opens the VS for you, but you find the solution file ( teste.sln , in my example) in the build folder you used.

Then, just open Visual Studio, compile and be happy! :)

#include<QApplication>#include<QLabel>intmain(intargc,char*argv[]){QApplicationapp(argc,argv);QLabel*window=newQLabel();window->setAlignment(Qt::AlignCenter);window->setStyleSheet("QLabel { font: 50px; background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 1, stop: 0.2 #ffcece, stop: 1.0 #ceffce); }");
    window->setWordWrap(true);

    window->setFixedSize(700, 400);
    window->setWindowTitle("Olá Mundo!");

    window->setText("Bem vindo ao teste de Qt 5 com Visual Studio 2015 para o Stack Overflow em Português!");

    window->show();
    return app.exec();
}

    
18.01.2017 / 15:15
1

I think you just missed downloading the:

It's too much at the bottom of the page and sometimes goes unnoticed: link

Note that there are 2:

In your specific case, the 1.2.5 version only works for VS2013 and you installed the VS-Add-in 2.0.0 for Qt5 MSVC 2013 > will not work at all.

I have had difficulty installing since until a few months the VS-Add-in 2.0.0 for Qt5 MSVC 2015 was beta and was not available on the page, I had which I download from the repository, but I believe it is stable.

    

18.01.2017 / 15:37