Using SFML with Qt creator? - c++

I've recently began learning the SFML API for learning purposes but it seems to me like it only supports Codeblocks IDE and Visual Studio. I dislike both IDEs for my own ideas and I like the IDE that comes with Qt instead.
Is it possible to basically use SFML within the Qt creator?
EDIT:
I know some of you may some day find this on google, after struggling for 8 days to set up sfml to work with qt creator I've found the sollution:
step 1: Download the VS version of SFML from the website (NOT codeblocks version)
step 2: copy the DLLs from C:\SFML-1.6\lib to your system32 directory
step 3: open qt creator, make a plain C++ project, open your .pro file and add these lines:
INCLUDEPATH += C:\SFML-1.6\include
LIBS += C:\SFML-1.6\lib\sfml-system.lib \
C:\SFML-1.6\lib\sfml-window.lib \
C:\SFML-1.6\lib\sfml-graphics.lib \
C:\SFML-1.6\lib\sfml-audio.lib \
C:\SFML-1.6\lib\sfml-network.lib
And you're done!

Short answer: Yes.
The IDE doesn't really matter all that much. The compiler does. Depending on the compiler used by Qt Creator, you download the appropriate SFML package. Most likely the MinGW based version will work just fine with your default install of Qt Creator. (I believe that relies on MinGW?)
All that then remains to be done is place SFML in its own directory and making sure that you set up the correct paths in your Qt Creator project. There's not much to it really.

I know i'm a little bit late to the party but:
SFML library is 100% compatible with qtcreator especially qmake.
Download SFML from https://www.sfml-dev.org/download/sfml/2.5.1/ . Bottom right minGW (You most likely have mingw on qt)
Place it somewhere you will know where it is. I usually put it in "C:/SFML-2.5.1"
There's a simple copy pasta you can add to your qmake '.pro' file:
INCLUDEPATH += "C:/SFML-2.5.1/include"
LIBS += -L"C:/SFML-2.5.1/lib"
CONFIG(debug, debug|release){
LIBS += -lsfml-audio-d -lsfml-graphics-d -lsfml-network-d -lsfml-system-d -lsfml-window-d
} else {
LIBS += -lsfml-audio -lsfml-graphics -lsfml-network -lsfml-system -lsfml-window
}
The 'INCLUDEPATH' includes the headers into your project where as the 'LIBS' adds the library file path. The 'CONFIG()' tells qt if you're running DEBUG mode or RELEASE mode.
This copy pasta is fun because you can also configure a custom wizard and make qt dropdown show you a 'create new sfml c++' project by just editing its profile with this.
Last but not least are the needed .dll files from 'C:\SFML-2.5.1\bin' You can add only the ones you need or all of them if you're lazy. You can do this by copying them into the BUILD folder of your project. (to find the build folder by default its a folder in the same path as your project folder with the name of your project prefixed by 'build-' or 'release-')

Make simple c++ project
Choose QMake build system
in project.pro add 2 lines:
CONFIG += link_pkgconfig
PKGCONFIG += sfml-all

Related

QT build errors with plugin / sdk library (autodesk fbx sdk)

I have just learned to configure my VS console app to use the Autodesk fbx plugin (vs2017). I am trying now to embed it in QT creator but it does not seem to work: the project does not build because of undefined references. obviously it is no able to attach one of the sdk's components but I don't know why this is happening.
in my .pro file, I have added the following:
LIBS += "E:/misc/fbx sdk/2020.0.1/lib/vs2017/x86/release/libfbxsdk.lib"
LIBS += "E:/misc/fbx sdk/2020.0.1/lib/vx2017/x86/release/libfbxsdk.dll"
INCLUDEPATH += "E:/misc/fbx sdk/2020.0.1/include"
DEPENDPATH += "E:/misc/fbx sdk/2020.0.1/lib/vs2017/x86"
This should have added the libfbxsdk.lib runtime lib to the project, and I also referenced the .dll there but that couldn't be the issue because the error would fire at run time.. Includes should be fine because the headers are included properly as well. Do you have any idea why this might be happening?
Here are the errors:
Do I understand correctly that these must have been declared in the .lib? But QT still does not see them?
I finally got this working. First, my attempt at a logical explanation...
The fbx sdk package that I have downloaded is specifically for Visual Studio 2017. Additionally, I aim at 32 bit. Now, Visual Studio's native compiler is MSVC, and this is what defines the toolchain including linking, compilation etc. QT's default compiler (at least for me) is g++. I cannot give you any good explanation but that was the reason why the linker in QT has been failing: you have to compile and link the sdk with the toolchain it was designed for. That is, with MSVC compiler and, for me, 32 bit architecture.
The steps:
1. You have to install a version of QT compiled with MSVC. I installed Qt 5.12.2 MSVC 2017 32-bit (2017 because I have downloaded the SDK for VS 2017)
2. Having installed this, you have to select the appropriate toolchain in the QT creator: this can be done in kits. Go to kits and directly select there the MSVC kit. It should be available after you have installed everything from (1.). Note that other kits previously active have to be deactivated by right-clicking on them and choosing the option. The kits can be managed in the 'Projects' tab.
3. After that, you can include your paths to the project AND link the libs - statically or dynamically. If you link dynamically, you have to manage the .dll as well (I placed it in the folder with the build of the project. If you link statically, you have to link all relevant .libs - for example, I first skipped the xml.lib which has lead to linker errors again.
See my .pro includes / adds below:
INCLUDEPATH += "E:/misc/fbx sdk/2020.0.1/include"
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/'../../../misc/fbx sdk/2020.0.1/lib/vs2017/x86/release/' -llibfbxsdk
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/'../../../misc/fbx sdk/2020.0.1/lib/vs2017/x86/debug/' -llibfbxsdk
INCLUDEPATH += $$PWD/'../../../misc/fbx sdk/2020.0.1/lib/vs2017/x86/release'
DEPENDPATH += $$PWD/'../../../misc/fbx sdk/2020.0.1/lib/vs2017/x86/release'
I have achieved the library includes with the QT wizard: right-click on the project for that, and choose 'Add libraries'. Then choose 'External library', specify the path, and choose to link it dynamically or statically.
If you happen to have run into the same problem and have questions re/ this, feel free to drop a line in comments.

Qt 5 and LibVLC

I'm working on a project which involves receive, display and rebroadcast several local network video streams. LibVLC seems to be the way to go, I'd like to use it within Qt Creator/C++/OSX 10.12.1 and I also need the project to be compilable on some Windows 10 machines where I have Qt installed.
I successfully tested some functionalities by installing the offical QT-LibVLC wrapper from projects.tano.si/vlc-qt. Unfortunately the wrapper lacks many LibVLC methods which are essential to my project, so I decided to install full LibVLC.
For now I'm stuck on how to make LibVLC work.
I followed all directions at https://wiki.videolan.org/OSXCompile/#Apple_Software
for installation and libraries building, and everything went fine.
Then I started a new project in QT, tried adding INCLUDEPATH += . vlc and LIBS +=-lvlc paths to the .pro file in Qt, but it does not work. Also adding paths to the "Framework" folder of the VLC build folder doesn't work.
Anyone knows how the magic trick?
Sorry, I know I'm a bit naive, but that's it...
Thank you in advance for any answer!
UPDATE:
thanks to eyllanesc suggestion this structure now works for the compiler:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = testVLC
TEMPLATE = app
DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += \
player.cpp \
main.cpp
HEADERS += \
player.h
macx: LIBS += -L$$PWD/../../../../Users/macbookpro15retina/Documents/vlc/build/vlc_install_dir/lib/ -lvlc.5
INCLUDEPATH += $$PWD/../../../../Users/macbookpro15retina/Documents/vlc/build/vlc_install_dir/include
DEPENDPATH += $$PWD/../../../../Users/macbookpro15retina/Documents/vlc/build/vlc_install_dir/include
Unfortunately the application is launched but VLC instance is not initialized. Seems that my VLC installation has something wrong.
SOLVED:
After some tweaking the project compiles and starts correctly.
I don't understand why, but the environment variable VLC_PLUGIN_PATH has to be set just before instantiating VLC, otherwise VLC refuses to initialize:
//set environment variable VLC_PLUGIN_PATH
int s = setenv ("VLC_PLUGIN_PATH", "/Users/macbookpro15retina/Documents/vlc/build/vlc_install_dir/lib/vlc/plugins", 1);
// Initialize libVLC
vlcInstance = libvlc_new(0, NULL);
Actually it doesn't work at all if you set it in the Build Environment of QtCreator.
A simple way to include libraries for our application is with the help of Qt Creator, this one has an assistant, to be able to use it just right click on the name of your project:
Then select the Add Library option.
Then the assistant opened:
And select the type of import, in your case it is advisable to use External Library.
Then you look for the location of your project and you accept.
Note: In Linux this tool can be opened with the shortcut Ctrl + E

z.lib problems while porting qt creator projet to windows

I am trying to port a Qt5.9 project from Mac to Windows 10.
I was able to compile the project easily in a ubuntu installation.
While trying to build it for windows, i had problems with finding zlib include headers with
#include<zlib.h>
That i corrected after following answers here on Stack to
#include<QtZlib/zlib.h>
Now i have problems in LINK phase, it can not open the file z.lib
Problem is i downloaded zlib packages, builds, source code and could not find a z.lib. Only different named libs. Searching in google i could only find people with the same problem, z.lib is not one of the libs included in zlib installation.
This is my project file:
TEMPLATE = app
QT += qml quick widgets websockets
CONFIG += c++11
SOURCES += \
main.cpp \
api.cpp \
app.cpp
HEADERS += \
api.hpp \
app.hpp
RESOURCES += qml.qrc
LIBS += -lz
I tried putting all possible dll and lib files in the project folder. None of them is named z.lib though.
The symbols for zlib are already part of the qt libraries. As long as you do not try to link the zlib explicitly it should work. At least it does work for me.
add to your project file:
!win32 {
LIBS += -lz
}
I managed to solve my problem updating my Qt installation to use MinGw 5.3 32bit. I was using VisualStudio 2015 as the compiler before.
Only changing the compiler to MinGw (g++) 5.3 made everything work with the same pro file i posted in the original question. Thanks everybody who tried to help!

Is it possible to use Qt Creator without qmake?

I've heard that it is possible to build non-Qt applications (like simple C++ HelloWorld) with Qt Creator. I downloaded and installed Qt Creator, and tried to compile simple code with it. But I didn't succeed: Creator needs qmake to create makefile.
Although the package I downloaded includes MinGW, there is no qmake inside of it.
I still want to use it just like an IDE to create simple C++ sources and compile them with MinGW. Is it possible to use Qt Creator without installing whole platform?
Qt Creator support CMake projects, you just need to choose Open a file or project and select the root CMakeList.txt of your project.
If you want to define your own build workflow, you can remove the default build step and create your own custom build steps (Qt Creator Build Steps).
I think you can modify the build step to remove qmake and use your custom make file.
You totally can!
You can write a .pro file yourself and use it as a project file to use QtCreator without linking / using any of the Qt libraries.
In Project / Compilation Parameters, you can actually tune the compilation steps (removing the qmake step and adding your own).
I use it for a big project of mine and it's very efficient: QtCreator's C analyzer is diamond.
Here's a sample project file for me:
TEMPLATE = app
TARGET =
DEPENDPATH += . include
INCLUDEPATH += . include
# Input
HEADERS += include/x.h \
include/y.h \
include/z.h
SOURCES += src/x.cpp
Note that I actually use qmake to generate this file automatically, but you can also put your hands into it and modify it by hand.
Afterwards, it's only a matter of $ qtcreator yourfile.pro.

linking mac framework to qt creator

I have a project that uses SystemConfiguration.Framework.
I've been using xcode, where adding the framework is quite easy, just add it to xcode project's framework. But now, I need my project to be cross platform, so I'm using QT Creator as a single IDE, for Windows and Mac. The problem is that I don't know how to tell QT Creator how to link to the systemConfiguration.framework. The header from the framework are correctly included, no problem there... just when is ending the compilation it complains that some symbols where not found, i.e, the symbols that are exported from the systemconfiguration.framework...
Does anyone knows or can help me to set up the Qt creator project to link agains that framework, please?
I assume the project itself is using Qt i.e. it is using .pro files to configure things like include paths and library/framework paths? If so then you just need to update the relevant .pro file to add the framework.
See the qmake docs for more detail. The gist of it is to add
QMAKE_LFLAGS += -F/path/to/framework/directory/
and
LIBS += -framework TheFramework
I found a solution which works with Qt 5.6 here:
https://doc.qt.io/qt-5/qmake-platform-notes.html#creating-frameworks
Using Frameworks
qmake is able to automatically generate build rules for linking
against frameworks in the standard framework directory on macOS,
located at /Library/Frameworks/.
Directories other than the standard framework directory need to be
specified to the build system, and this is achieved by appending
linker options to the LIBS variable, as shown in the following
example:
LIBS += -F/path/to/framework/directory/
The framework itself is linked in by appending the -framework options and the > name of the framework to the LIBS variable:
LIBS += -framework TheFramework