How do I get Qt 5.7 with MSVC2015 to work?

Asked

Viewed 470 times

2

I’ve had Microsoft Visual Studio Community 2015 for a long time.

I installed Qt 5.7 via online installer and includes msvc2015 (already marked) in the list of installation programs. I tried using Qt Creator, but it gives a build 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\5.8\msvc2015_64\include -IC:\Qt\5.8\msvc2015_64\include\QtWidgets -IC:\Qt\5.8\msvc2015_64\include\QtGui -IC:\Qt\5.8\msvc2015_64\include\QtANGLE -IC:\Qt\5.8\msvc2015_64\include\QtCore -Idebug -I. -IC:\Qt\5.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\5.8\msvc2015_64\include -IC:\Qt\5.8\msvc2015_64\include\QtWidgets -IC:\Qt\5.8\msvc2015_64\include\QtGui -IC:\Qt\5.8\msvc2015_64\include\QtANGLE -IC:\Qt\5.8\msvc2015_64\include\QtCore -Idebug -I. -IC:\Qt\5.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 from the site and installed "Qt VS Tools MSVC 2015". Appeared in Visual Studio the option to create GUI project of Qt...

Criação do projeto do Qt no VS.

...but when trying to create a project occurs the error below.

Erro que aparece ao confirmar a criação do projeto.

What do I do to finally use Qt?

2 answers

2

Your Qtcreator error is probably some wrong configuration even (as the error message indicates). If you’re going to use it, I suggest you try to recreate the 2015 VS Kit (follow the Qt Creator documentation).

About VS Toolkit, I don’t know how to help. I never liked this tool because it is hard to understand and use and almost always gives some problem. Out that it has serious difficulties of updating between versions of Visual Studio. That video can be useful (I don’t know if you’re up to date) and maybe another colleague who works with Qt ( @Guilhermenascimento most likely! rs) can help you with this.

But it is possible to generate Visual Studio files directly from the project file ( .pro file) using the qmake. And the advantage of using qmake is that you gain portability: you can generate VS project files on Windows or Make files (Makefiles) on Linux, for example.

I used to use this script (with extension . cmd) that worked on both Windows (as batch script) and Linux (as 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

He uses a cool "trick" (described in this reply by Soen) to be able to run on both Windows and Linux.

But in the last few years I’ve traded all this for the use of Cmake. Besides being a fantastic free tool, it makes it very easy to work when you want portability, and many of the projects open source use it (which also facilitates integration when these projects are used). She has a little learning curve, of course, but it’s worth a lot of time. With Cmake I don’t even have to worry about the directories where the dependencies are, and it is able to generate and maintain Visual Studio 2015 project files (and you never again you will need to warm your head with the VS Toolkit!).

Here’s an example file CMakeLists.txt (which is at the root of your project, and which contains your configuration for Cmake):

# 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})`
#

To use it, just open Cmake, set the project directory (where the CMakeLists.txt) and "build" (where the VS project will be generated, and where compiled files will be produced when you work inside the VS; this can be any path, and you can delete it and generate it again if you need to - so it’s good to keep it separate).

In my example I have the following structure at the root of the project:

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

And for convenience, I managed the binaries in:

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

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

After opening Cmake I set 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 version "14" (because of Microsoft’s idiosyncrasies). Also remember to choose the 32 or 64 bit version depending on your Qt installation. After confirming it will read the configuration and prepare the project:

inserir a descrição da imagem aqui

(Do not be alarmed by the red color. It does not indicate error. Only that variables have been found. Cmake allows you to change variables via this interface, which is often useful).

Now just click on "Generate" that the project will be generated (or updated if you made any changes to an already generated project). The "Open Project" button opens VS alone 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! :)

inserir a descrição da imagem aqui

#include <QApplication>
#include <QLabel>

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QLabel *window = new QLabel();

    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();
}

inserir a descrição da imagem aqui

  • 1

    Thanks for quoting me, really Qt+MSVC is something complicated, but for the error I’m almost sure is the lack of the correct vsaddin, it may have installed 1.2.5 or it may have installed version 2.0.0 for VS2013.

1

I guess I just had to lower the:

http://download.qt.io/official_releases/vsaddin/qt-vs-tools-msvc2015-2.0.0.vsix

It’s just that it’s at the very end of the page and sometimes goes unnoticed: https://www.qt.io/download-open-source/#Section-10

Note that there are 2:

downloads

In your specific case is the last, the version 1.2.5 only works for VS2013 and if installed the VS-Add-in 2.0.0 for Qt5 MSVC 2013 won’t work at all.

I had difficulty installing because until a few months ago the VS-Add-in 2.0.0 for Qt5 MSVC 2015 era beta and it wasn’t available on the page, I had to download it from the repository, but I think it’s stable.

  • 1

    It is. Precisely because of these difficulties that I gave up using a long time ago. :)

  • Actually I took a long time to notice him, but I had already installed and tested with him when I posted. So the problem is another.

  • @RHERWOLF sure you installed the correct one? Tried to uninstall and install again?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.