After spending a day working through and trying (and eventually succeeding) to get QT to work with SFML, I wouldn't wish the frustration I have had today upon anyone. Hence, I wish to provide the configuration steps for QT so that it can be put onto a page on the main SFML website alongside the configuration for MinGW and MSVC.
Here goes
- Download the Source for the SFML version you intend to use and extract it to a folder
- Open QT Creator
- Go to: Tools->Options->Build & Run->CMake and make sure that CMake has been either Autodetected or manually set
- Go to the Welcome tab and click the "Open Project..." button
- Look for the CMakelists.txt file in the SFML source folder
- Click on the Projects icon on the left hand side of the IDE. Choose Build Settings from the Build And Run menu. Scroll down to and expand the Build Environment roll-out in order to look for the PATH variable. Make sure that the following exists in the Path variable: C:\QtSDK\mingw\bin;C:\qtsdk\qt\bin;
- Set the CMake parameters that you need (for me, BUILD_SHARED_LIBS=False and SFML_USE_STATIC_STD_LIBS=True) and click Apply Configuration Changes (Make sure to set the Build Directory to something like "<SFML_Source_Root>..\SFML-Build\<Build_Configuration>" to make the Project Configuration later easier)
- Click the Hammer in the bottom-left corner to build the current Build Configuration (Do this for both Debug and Release)
- Go to File->New File Or Project->Non-Qt Project->Plain C++ Application->Choose
- Click Choose. Name your project. The rest of the Project Setup can be left as the default
- Open the Project's .pro file and replace the contents with the following (Variables have been used so you only need to replace 2 paths with your paths)
TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG -= qt
#Absolute Paths (Set to your Directory Configurations)
SFML_SOURCE_ROOT = W:\SFML-2.4.2
SFML_BINARIES_ROOT = W:\SFML-Build
#I built the SFML libs separating the Release and Debug versions.
#If you have a different setup, please, either modify these
#variables or (if you are worried about screwing things up)
#modify your directory hierachy to match this structure
SFML_BINARIES_DEBUG = $${SFML_BINARIES_ROOT}\Debug
SFML_BINARIES_RELEASE = $${SFML_BINARIES_ROOT}\Release
#SFML Lib Directories
LIBS += -L$${SFML_BINARIES_DEBUG}\lib #Debug Core Libs
LIBS += -L$${SFML_BINARIES_RELEASE}\lib #Release Core Libs
LIBS += -L$${SFML_SOURCE_ROOT}\extlibs\libs-mingw\x86 #External Libs
#Release Configuration
CONFIG(release, debug|release):
{
#Audio Related Libs
LIBS += -llibsfml-audio-s #SFML Static Module
LIBS += -llibopenal32 #Dependency
LIBS += -llibFLAC #Dependency
LIBS += -llibvorbisenc #Dependency
LIBS += -llibvorbisfile #Dependency
LIBS += -llibvorbis #Dependency
LIBS += -llibogg #Dependency
#SFML-Graphics Libs
LIBS += -llibsfml-graphics-s #SFML Static Module
LIBS += -llibfreetype #Dependency
LIBS += -llibjpeg #Dependency
#SFML-Network Libs
LIBS += -llibsfml-network-s #SFML Static Module
LIBS += -lws2_32 #Dependency
#SFML-Window Libs
LIBS += -llibsfml-window-s #SFML Static Module
LIBS += -lopengl32 #Dependency
LIBS += -lgdi32 #Dependency
#SFML-System Libs
LIBS += -llibsfml-system-s #SFML Static Module
LIBS += -lwinmm #Dependency
}
#Debug Configuration
CONFIG(debug, debug|release):
{
#Audio Related Libs
LIBS += -llibsfml-audio-s-d #SFML Static Module
LIBS += -llibopenal32 #Dependency
LIBS += -llibFLAC #Dependency
LIBS += -llibvorbisenc #Dependency
LIBS += -llibvorbisfile #Dependency
LIBS += -llibvorbis #Dependency
LIBS += -llibogg #Dependency
#SFML-Graphics Libs
LIBS += -llibsfml-graphics-s-d #SFML Static Module
LIBS += -llibfreetype #Dependency
LIBS += -llibjpeg #Dependency
#SFML-Network Libs
LIBS += -llibsfml-network-s-d #SFML Static Module
LIBS += -lws2_32 #Dependency
#SFML-Window Libs
LIBS += -llibsfml-window-s-d #SFML Static Module
LIBS += -lopengl32 #Dependency
LIBS += -lgdi32 #Dependency
#SFML-System Libs
LIBS += -llibsfml-system-s-d #SFML Static Module
LIBS += -lwinmm #Dependency
}
INCLUDEPATH += $${SFML_SOURCE_ROOT}\include
DEPENDPATH += $${SFML_SOURCE_ROOT}\include
#Preprocessor Macros
DEFINES += SFML_STATIC
#Source Files
SOURCES += main.cpp
Replace the contents of main.cpp with the following
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
sf::CircleShape shape(100.f);
shape.setFillColor(sf::Color::Green);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(shape);
window.display();
}
return 0;
}
And compile.