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:
(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! :)
#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();
}
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.
– Guilherme Nascimento