Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Integrating Qt 5.4 with SFML 2.0  (Read 8575 times)

0 Members and 2 Guests are viewing this topic.

WDR

  • Jr. Member
  • **
  • Posts: 82
    • View Profile
Integrating Qt 5.4 with SFML 2.0
« on: March 14, 2015, 09:11:25 am »
Hi... Can anyone please tell me why there are no proper tutorials on how to include SFML libraries in the Qt IDE, text-based, video-based or otherwise? I have searched a lot and done everything humanely possible to make it work, but I'm not able to do so. I came across one, and only one, proper tutorial, which is: https://github.com/SFML/SFML/wiki/Tutorial%3A-Compile-and-Link-SFML-with-Qt-Creator

The tutorial is step wise, and for some reason, I am not able to get past step 5 for Windows. The IDE does not allow me to do step 6. Because after doing step 5, the window that opens does not close until you do step 8. I am not able to do step 6 and 7 which results in the libraries compiling wrong. Can someone please help me on how I would do this? Thanks. I am using Qt 5.4 and SFML 2.0.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Integrating Qt 5.4 with SFML 2.0
« Reply #1 on: March 14, 2015, 09:32:11 am »
This tutorial explains how to compile SFML. You probably don't need to do it. And to use SFML, you just need to do like for any other library: add its include path to the INCLUDEPATH QMake variable and add the libraries to the LIBS variable, in your .pro file. If you don't know how to do that, I suggest that you read some documentation about QMake first.
Laurent Gomila - SFML developer

WDR

  • Jr. Member
  • **
  • Posts: 82
    • View Profile
Re: Integrating Qt 5.4 with SFML 2.0
« Reply #2 on: March 14, 2015, 10:01:33 am »
OK... Thanks for your prompt reply, Laurent. I have a doubt, though. I'm assuming the libraries that I have to include are not the same ones used for Visual Studio. Because I tried that, and I couldn't use the libraries. So, I assumed I would have to use ones separately compiled for Qt. Hence, my attempts at compiling the libraries again. Please clarify whether they are different for different IDEs. I'll also check out QMake. Thank you.

EDIT: Here's what I did,

#-------------------------------------------------
#
# Project created by QtCreator 2015-03-10T18:52:16
#
#-------------------------------------------------

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = RTS_Resource_Manager
TEMPLATE = app


SOURCES += main.cpp\
        RTS_Resource_Manager.cpp

HEADERS  += RTS_Resource_Manager.h

FORMS    += RTS_Resource_Manager.ui

LIBS += -LC:/Users/WDR/Documents/Visual Studio 2010/SFML-2.0/lib

CONFIG(release, debug|release): LIBS += -lsfml-audio -lsfml-graphics -lsfml-main -lsfml-network -lsfml-window -lsfml-system
CONFIG(debug, debug|release): LIBS += -lsfml-audio-d -lsfml-graphics-d -lsfml-main-d -lsfml-network-d -lsfml-window-d -lsfml-system-d

INCLUDEPATH += C:/Users/WDR/Documents/Visual Studio 2010/SFML-2.0/include
DEPENDPATH += C:/Users/WDR/Documents/Visual Studio 2010/SFML-2.0/include
 

Anything wrong with the above .pro file? Please tell me. Thanks!
« Last Edit: March 14, 2015, 10:11:47 am by WDR »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Integrating Qt 5.4 with SFML 2.0
« Reply #3 on: March 14, 2015, 11:34:17 am »
QtCreator is just an IDE, not a compiler. It can use either MinGW (gcc) or the Visual C++ compiler. By default it comes with MinGW. So you must check which version of MinGW you're using and download the matching SFML package.
Laurent Gomila - SFML developer

WDR

  • Jr. Member
  • **
  • Posts: 82
    • View Profile
Re: Integrating Qt 5.4 with SFML 2.0
« Reply #4 on: March 14, 2015, 12:32:01 pm »
Laurent, I am using Qt Creator with Desktop Qt 5.4 MSVC2010 OpenGL 32bit as a building kit which uses Microsoft Visual C++ Compiler 10.0 (32bit) as the compiler. So, I am using the right SFML package (The one I downloaded for using in MS Visual Studio 10). I don't know why I am not able to get it to work.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Integrating Qt 5.4 with SFML 2.0
« Reply #5 on: March 14, 2015, 12:55:36 pm »
Yes, you have the right package. If you have problems then describe them so that we can help you.
Laurent Gomila - SFML developer

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Integrating Qt 5.4 with SFML 2.0
« Reply #6 on: March 14, 2015, 12:59:07 pm »
If you already have SFML as compiled binaries you don't need to fully follow that tutorial, because the tutorial explains how to build SFML.
So what you need is essentially just the linking part. However I'm not sure if that will also work with VS 2010, because the commands look more like GCC commands.
« Last Edit: March 14, 2015, 01:33:07 pm by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

WDR

  • Jr. Member
  • **
  • Posts: 82
    • View Profile
Re: Integrating Qt 5.4 with SFML 2.0
« Reply #7 on: March 14, 2015, 01:07:27 pm »
Yes, you have the right package. If you have problems then describe them so that we can help you.

That's the thing. I am not able to get it to work. My .pro file looks exactly like I posted above and the directories shown are correct. But, when I try to include any one of the SFML headers in my .cpp file, they don't show up on the IntelliSense and are also not read by the program. I can't use any of the functions from that header. I don't know why. I looked up the project properties and it does show that it is using the VC++ compiler.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Integrating Qt 5.4 with SFML 2.0
« Reply #8 on: March 14, 2015, 01:32:48 pm »
IntelliSense is a Mircosoft product built into Visual Studio.

So did you try to read the Qt Creator docs or at least google for how to link libraries with Qt Creator and the VS compiler?
Just because someone wrote a random tutorial on a wiki that everyone can use and edit, doesn't mean that it will actually work in all cases. :D
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Integrating Qt 5.4 with SFML 2.0
« Reply #9 on: March 14, 2015, 01:55:07 pm »
Your .pro is almost ok: you should surround your paths with double-quotes (they contain spaces). Then, don't rely on the auto-completion of the IDE, it has bugs. Compile your code and check the compiler errors.
Laurent Gomila - SFML developer

WDR

  • Jr. Member
  • **
  • Posts: 82
    • View Profile
Re: Integrating Qt 5.4 with SFML 2.0
« Reply #10 on: March 14, 2015, 02:49:44 pm »
Well, that did the trick. All this time it was only because of the double quotes. It was the Programmer's Semicolon Syndrome all over again (No need to google that, I made it up. But you know what it means.  ;)).

@eXpl0it3r: You know what I meant by IntelliSense. Like Laurent pointed out, it was auto-completion. Didn't really know the exact terminology. And I did read about linking, I could link Box2D libraries perfectly fine.

@Laurent: Thanks for telling me that. I have written code and tried to compile it, but I am getting an error saying,

C:\Users\WDR\Documents\Qt\RTS_Resource_Manager\RTS_Resource_Manager.cpp:3: error: C1083: Cannot open include file: 'Graphics.hpp': No such file or directory

The include path in the .pro file is updated to show,

INCLUDEPATH += "C:/Users/WDR/Documents/Visual Studio 2010/SFML-2.0/include/SFML"
DEPENDPATH += "C:/Users/WDR/Documents/Visual Studio 2010/SFML-2.0/include/SFML"

That is the only problem I am getting. Please tell me why this is happening. Thank you so far for all the help.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Integrating Qt 5.4 with SFML 2.0
« Reply #11 on: March 14, 2015, 05:28:01 pm »
The include path should be "SFML-2.0/include" and you should include <SFML/Graphics.hpp>. But that shouldn't change anything to your problem. Check the full compiler output (window number 4) and see if your include path is there (behind a -I).
Laurent Gomila - SFML developer

WDR

  • Jr. Member
  • **
  • Posts: 82
    • View Profile
Re: Integrating Qt 5.4 with SFML 2.0
« Reply #12 on: March 14, 2015, 05:59:33 pm »
Well, I usually keep it as "SFML-2.0/include" but I thought the error might be due to forward slash or backward slash in the <SFML/Graphics.hpp> (Now I know it makes no difference in this case). So, to avoid confusion, I did that.

I checked the full compile output and as you said there is no -I for this include path. The path itself is also not there. How would I fix this?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Integrating Qt 5.4 with SFML 2.0
« Reply #13 on: March 14, 2015, 06:07:15 pm »
No idea. Right click on project, then "Run QMake" and "Rebuild"? :D
Laurent Gomila - SFML developer

WDR

  • Jr. Member
  • **
  • Posts: 82
    • View Profile
Re: Integrating Qt 5.4 with SFML 2.0
« Reply #14 on: March 14, 2015, 07:25:13 pm »
Well, I don't know whether you were joking or just being cheery in general, but that worked. I'm not getting any more errors. But the bad news is, I'm not getting an SFML window either. I tried to do a test program to see how it worked. The program compiles fine but I am not getting an output window like I should. Here's the program,

#include<SFML/Graphics.hpp>
#include<SFML/Window.hpp>

int main()
{
    sf::RenderWindow Window(sf::VideoMode(300, 300), "Window");

    while(Window.isOpen())
    {
        sf::Event Window_Event;
       
        Window.pollEvent(Window_Event);
       
        do
        {
            if(Window_Event.type == sf::Event::Closed)
            {
                Window.close();
            }
        }
        while(Window.pollEvent(Window_Event));

        Window.clear();
       
        Window.display();
    }

    return 0;
}

Any idea why that is happening? Please help!  :-\
« Last Edit: March 15, 2015, 06:51:48 am by WDR »