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

Author Topic: qualified-id in declaration before ‘event’  (Read 642 times)

0 Members and 1 Guest are viewing this topic.

branrjab

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
qualified-id in declaration before ‘event’
« on: April 29, 2025, 09:27:19 pm »
I'm new to SFML but I installed on Windows 11 and tried a sample program and it worked first try.
Impressive.

I installed on new minimal install of  Ubuntu 20.04 with only gcc and sfml added and it failed. I suspect it's some trivial problem but I cannot find it after extensive searches.

I also tried it on Ubuntu 24.04 with the same result.

Here's the compile command and the error I get:

------------------------------

jimbrown@Ub20:~$ g++  -O0 -g3 -Wall  "sfmltest.cpp"
sfmltest.cpp: In function ‘int main(int, char**)’:
sfmltest.cpp:14:36: error: qualified-id in declaration before ‘event’
   14 |         while (const std::optional event = window.pollEvent())
      |                                    ^~~~~
sfmltest.cpp:16:17: error: ‘event’ was not declared in this scope
   16 |             if (event->is<sf::Event::Closed>())
      |                 ^~~~~
sfmltest.cpp:16:46: error: expected primary-expression before ‘)’ token
   16 |             if (event->is<sf::Event::Closed>())
      |

------------------------------

Here's the program - mostly from a sample on the web with some added undef's because of a suggetion I found while searching:

#undef Status
#undef None
#undef BadRequest
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>

int main(int argc, char** argv) {
    sf::RenderWindow window(sf::VideoMode({ 200, 200 }), "SFML works!");
    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);

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

        window.clear();
        window.draw(shape);
        window.display();
    }
} //end main
« Last Edit: April 30, 2025, 08:10:24 am by eXpl0it3r »

kimci86

  • Full Member
  • ***
  • Posts: 130
    • View Profile
Re: qualified-id in declaration before ‘event’
« Reply #1 on: April 29, 2025, 10:16:38 pm »
What version of SFML did you install?
It looks like you are trying to use SFML 3 while having SFML 2.6 or earlier installed.

Once you install SFML 3, then you would also need to tell the compiler to use C++17 or higher, adding -std=c++17 to your compilation command line.
Eventually, you can setup a CMake project to take care of this detail.

branrjab

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: qualified-id in declaration before ‘event’
« Reply #2 on: May 01, 2025, 12:40:38 am »
WOW! Thanks. You pegged it perfectly.

I manually installed on Windows and choose 3.0. For Ubuntu I used the package manager and the command  apt-get install libsfml-dev    which installed Version 2.5.1.

I now know how to check what version by looking at the Config.hpp

I'll see if I can figure out how to install 3.0 on Ubuntu,

Thanks so much for the help.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11193
    • View Profile
    • development blog
    • Email
Re: qualified-id in declaration before ‘event’
« Reply #3 on: May 01, 2025, 08:02:45 am »
Ubuntu doesn't yet ship SFML  in the package manager, or rather only on experimental.

We usually recommend to use the CMake template, that will automatically build SFML for you: https://github.com/SFML/cmake-sfml-project
Official FAQ: https://www.sfml-dev.org/faq/
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything