class sf :: RenderWindow'没有名为'clear'的成员

时间:2013-12-02 03:01:56

标签: c++ libraries sfml

我花了至少5个小时试图让sfml库与我的QT-creator ide一起工作。我已经按照本教程https://github.com/LaurentGomila/SFML/wiki/Tutorial%3A-Compile-and-Link-SFML-with-Qt-Creator进行了操作,但仍然没有运气。
在构建简单代码后,我不断得到类成员不存在的错误。我可以创建类的实例,但在尝试使用时会出现多个错误
创建对象的成员。我已经尝试查找库相关的问题,sfml问题,但我不认为我正在寻找正确的问题。

这样可以显示一个窗口,该窗口在强制程序退出之前永远不会关闭:

#include <SFML/Graphics.hpp>

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

    while (true)//window.isOpen())
    {
        sf::Event event;
        /*while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }*/

        //window.clear();
        //window.draw(shape);
        //window.display();
    }

    return 0;
}

只要删除一条评论,就会弹出一条错误消息。我无法弄清楚我的生活发生了什么。

提前致谢。

额外信息

  • 操作系统: Ubuntu 12.10 Live(安装到硬盘)

  • 项目文件 我确定这是不正确的
  • TEMPLATE = app
    
    #CONFIG += console
    
    CONFIG -= qt
    
    SOURCES += main.cpp
    
    LIBS += -L"/home/user/Projects/SFML/lib"
    
    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 += "/home/user/Projects/SFML/include"
    
    DEPENDPATH += "/home/user/Projects/SFML/include"
    


  • 错误:  我将发布编译输出
  • main.cpp: In function 'int main()':
    
    main.cpp:6:5: error: 'CircleShape' is not a member of 'sf'
    
    main.cpp:6:21: error: expected ';' before 'shape'
    
    main.cpp:7:5: error: 'shape' was not declared in this scope
    
    main.cpp:12:23: error: 'class sf::RenderWindow' has no member named 'pollEvent'
    
    main.cpp:14:23: error: 'class sf::Event' has no member named 'type'
    
    main.cpp:15:24: error: 'class sf::RenderWindow' has no member named 'close'
    
    main.cpp:18:16: error: 'class sf::RenderWindow' has no member named 'clear'
    
    main.cpp:19:16: error: 'class sf::RenderWindow' has no member named 'draw'
    
    main.cpp:20:16: error: 'class sf::RenderWindow' has no member named 'display'
    
    16:25:10: The process "/usr/bin/make" exited with code 2.
    
    Error while building project sfmlTest (target: Desktop)
    
    When executing build step 'Make'
    

  • 执行路径
  • make: Leaving directory `/home/username/Documents/Projects/c++/Sfml/sfmlTest-build-desktop-Qt_4_8_1_in_PATH__System__Release'
    


  •  编译器使用:
  •  我相信Gnu编译器,G ++

    1 个答案:

    答案 0 :(得分:4)

    不是100%肯定,但是因为你在Ubuntu上,你很可能不是自己编译SFML,而是调用apt-get install sfml-dev而不是SFML 1.6而不是SFML 2.x.在SFML 1.6中,命名约定是CamelCase,并且已经将SFML 2.0更改为camelCase。

    既然你想要并且应该使用SFML 2.x,你需要使用SFML论坛中的unofficial package或者自己编译SFML。