最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c++ - compatibility errors with sfml and TGUI - Stack Overflow

programmeradmin1浏览0评论

was trying to add some new buttons and stuff to the project, but ended up with the following problems


16:04:54:436    1>D:\SFML-3.0.0\include\SFML\Window\Event.inl(45,19): error C2338: static_assert failed: 'TEventSubtype must be a subtype of sf::Event'

16:04:54:436    1>(compiling source file 'main.cpp')

16:04:54:436    1>    D:\SFML-3.0.0\include\SFML\Window\Event.inl(45,19):

16:04:54:436    1>    the template instantiation context (the oldest one first) is

16:04:54:436    1>        C:\Users\Username\source\repos\TGUI learning\main.cpp(32,20):

16:04:54:436    1>        see reference to function template instantiation 'sf::Event::Event<std::optional<sf::Event>>(const TEventSubtype &)' being compiled

16:04:54:436    1>        with

16:04:54:436    1>        [

16:04:54:436    1>            TEventSubtype=std::optional<sf::Event>

16:04:54:436    1>        ]

16:04:54:643    1>Done building project "TGUI learning.vcxproj" -- FAILED.

for some reason, the following code ends up with errors above

#include <TGUI/TGUI.hpp>
#include <TGUI/Core.hpp>
#include <TGUI/Backend/SFML-Graphics.hpp>
#include <SFML/Graphics.hpp>

int main() {

    sf::RenderWindow window(sf::VideoMode({ 800, 600 }), "TGUI learning");


    tgui::Gui gui(window);

    while (window.isOpen()) {
        while (const auto event = window.pollEvent()) {
            if (event->is<sf::Event::Closed>()) {
                window.close();
            } 

            gui.handleEvent(event);
        }
        window.clear();
        gui.draw();
        window.display();
    }


    return 0;

}

but the example on the TGUI learning page

#include <TGUI/TGUI.hpp>
#include <TGUI/Backend/SFML-Graphics.hpp>

int main() {

    sf::RenderWindow window(sf::VideoMode({ 800, 600 }), "TGUI learning");
    tgui::Gui gui{ window };
    gui.mainLoop(); // See below for how to use your own main loop
}

actually works

i have triple checked connection errors with sfml, TGUI, but it is not it, also if you comment the parts of the sfml/TGUI code that ends up with errors, it will compile and work just fine

//#include <TGUI/TGUI.hpp>
//#include <TGUI/Core.hpp>
//#include <TGUI/Backend/SFML-Graphics.hpp>
#include <SFML/Graphics.hpp>

int main() {

    sf::RenderWindow window(sf::VideoMode({ 800, 600 }), "TGUI learning");


    //tgui::Gui gui(window);

    while (window.isOpen()) {
        while (const auto event = window.pollEvent()) {
            if (event->is<sf::Event::Closed>()) {
                window.close();
            } 

            //gui.handleEvent(event);
        }
        window.clear();
        //gui.draw();
        window.display();
    }


    return 0;

}

so this code will actually work

was trying to add some new buttons and stuff to the project, but ended up with the following problems


16:04:54:436    1>D:\SFML-3.0.0\include\SFML\Window\Event.inl(45,19): error C2338: static_assert failed: 'TEventSubtype must be a subtype of sf::Event'

16:04:54:436    1>(compiling source file 'main.cpp')

16:04:54:436    1>    D:\SFML-3.0.0\include\SFML\Window\Event.inl(45,19):

16:04:54:436    1>    the template instantiation context (the oldest one first) is

16:04:54:436    1>        C:\Users\Username\source\repos\TGUI learning\main.cpp(32,20):

16:04:54:436    1>        see reference to function template instantiation 'sf::Event::Event<std::optional<sf::Event>>(const TEventSubtype &)' being compiled

16:04:54:436    1>        with

16:04:54:436    1>        [

16:04:54:436    1>            TEventSubtype=std::optional<sf::Event>

16:04:54:436    1>        ]

16:04:54:643    1>Done building project "TGUI learning.vcxproj" -- FAILED.

for some reason, the following code ends up with errors above

#include <TGUI/TGUI.hpp>
#include <TGUI/Core.hpp>
#include <TGUI/Backend/SFML-Graphics.hpp>
#include <SFML/Graphics.hpp>

int main() {

    sf::RenderWindow window(sf::VideoMode({ 800, 600 }), "TGUI learning");


    tgui::Gui gui(window);

    while (window.isOpen()) {
        while (const auto event = window.pollEvent()) {
            if (event->is<sf::Event::Closed>()) {
                window.close();
            } 

            gui.handleEvent(event);
        }
        window.clear();
        gui.draw();
        window.display();
    }


    return 0;

}

but the example on the TGUI learning page

#include <TGUI/TGUI.hpp>
#include <TGUI/Backend/SFML-Graphics.hpp>

int main() {

    sf::RenderWindow window(sf::VideoMode({ 800, 600 }), "TGUI learning");
    tgui::Gui gui{ window };
    gui.mainLoop(); // See below for how to use your own main loop
}

actually works

i have triple checked connection errors with sfml, TGUI, but it is not it, also if you comment the parts of the sfml/TGUI code that ends up with errors, it will compile and work just fine

//#include <TGUI/TGUI.hpp>
//#include <TGUI/Core.hpp>
//#include <TGUI/Backend/SFML-Graphics.hpp>
#include <SFML/Graphics.hpp>

int main() {

    sf::RenderWindow window(sf::VideoMode({ 800, 600 }), "TGUI learning");


    //tgui::Gui gui(window);

    while (window.isOpen()) {
        while (const auto event = window.pollEvent()) {
            if (event->is<sf::Event::Closed>()) {
                window.close();
            } 

            //gui.handleEvent(event);
        }
        window.clear();
        //gui.draw();
        window.display();
    }


    return 0;

}

so this code will actually work

Share Improve this question asked Mar 20 at 13:16 NeKonNeKon 298 bronze badges 2
  • Most of the time auto makes things better, but sometimes... Sometimes it hides the problem. – user4581301 Commented Mar 20 at 17:03
  • i knew that pollEvent returns pointer, i just didnt know that handleEvent takes value and not the pointer – NeKon Commented Mar 22 at 15:40
Add a comment  | 

1 Answer 1

Reset to default 0

the thing is that you need to handle events with tgui via giving not a pointer, but an actual value, so you need to firstly dereference it
gui.handleEvent(*event);

发布评论

评论列表(0)

  1. 暂无评论