SFML community forums
Help => General => Topic started by: krschnv on July 19, 2021, 07:03:53 pm
-
I found a way to connect SFML to the Qt Creator environment. I was already delighted, but then I tried to push code using both qt and sfml into the project and nothing worked. The fact is that in order to connect sfml to qt creator, you need to change the .pro file and move some directories with sfml files in directory of qt project. I wrote this in .pro file:
TEMPLATE = app
CONFIG -= qt
CONFIG += console
LIBS += -L/Users/vladimirkorsunov/QtProjects/untitled/untitled/Contents/Frameworks/
CONFIG (release, debug|release): LIBS += -lsfml-audio -lsfml-graphics -lsfml-network -lsfml-window -lsfml-system
CONFIG (debug, debug|release): LIBS += -lsfml-audio -lsfml-graphics -lsfml-network -lsfml-window -lsfml-system
INCLUDEPATH += /Users/vladimirkorsunov/QtProjects/untitled/
DEPENDPATH += /Users/vladimirkorsunov/QtProjects/untitled/
It works, but I can't use qt in this project, because I removed all, what was in .pro file before. I tried to add this code after code, which already was in .pro file, but it still doesen't work. My OS – Mac OS Big Sur, SFML version – 2.1 (Clang), project created whith qmake. If I remove first 3 lines of that code, compiler says that it can't find -lsfml-audio (library not found for -lsfml-audio), so problem in DEPENDPATH, but path is right! If I add that lines back compiler says, that 'QApplication' file not found, so I think it can't find Qt files. Here is whole code:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++11
# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
mainwindow.cpp
HEADERS += \
mainwindow.h
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
TEMPLATE = app
CONFIG -= qt
CONFIG += console
SOURCES += main.cpp
LIBS += -L/Users/vladimirkorsunov/QtProjects/untitled2/untitled2/Contents/Frameworks/
CONFIG (release, debug|release): LIBS += -lsfml-audio -lsfml-graphics -lsfml-network -lsfml-window -lsfml-system
CONFIG (debug, debug|release): LIBS += -lsfml-audio -lsfml-graphics -lsfml-network -lsfml-window -lsfml-system
INCLUDEPATH += /Users/vladimirkorsunov/QtProjects/untitled2/
DEPENDPATH += /Users/vladimirkorsunov/QtProjects/untitled2/
Can I use both SFML and Qt in one window? Maybe it is impossible? For example can I draw graphics via SFML and draw GUI via Qt? I saw only guid for using SFML in Qt Creator whithout Qt, but it's useless, because God gave me Xcode.
-
Are you trying to just use SFML in the Qt Creator or are you trying to integrate SFML into your Qt GUI?
For the first, it should be quite straight forward, by adding SFML like any other library.
Since Qt Creator supports it, I'd probably recommend going with a CMake project setup instead of a *.pro file.
If you want to integrate SFML into your Qt project, you'll need to create a special widget for that.
There are a bunch of examples out there already.
I think the most difficult part is how to deal with event handling, as both Qt and SFML will "consume" the events.
-
In case anyone else stumbles upon this, I have taken the example from sfml 1.6 (https://www.sfml-dev.org/tutorials/1.6/graphics-qt.php) and updated it:
https://github.com/thebruce87m/sfml-in-qt