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