首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Qt5.1和OpenGL中从“QAbstractOpenGLFunctions*”到“QOpenGLFunctions_4_3_Core*”的无效转换

Qt5.1和OpenGL中从“QAbstractOpenGLFunctions*”到“QOpenGLFunctions_4_3_Core*”的无效转换
EN

Stack Overflow用户
提问于 2013-07-15 04:32:03
回答 1查看 513关注 0票数 3

我正在通过引用OpenGL来学习K民建联文章第一部分。这是相当新的和有帮助的。但是,我在页面上尝试他的代码时遇到了编译错误。

在我的Qt项目中有三个文件: main.cpp、window.cpp和window.h。

窗口。h:

代码语言:javascript
复制
#ifndef WINDOW_H
#define WINDOW_H

#include <QWindow>
#include <QSurfaceFormat>
#include <QOpenGLContext>
#include <QOpenGLFunctions_4_3_Core>

class Window : public QWindow
{
    Q_OBJECT
public:
    Window(QScreen* screen);

signals:
private:
    QOpenGLContext *m_context;
    QOpenGLFunctions_4_3_Core* m_funcs;
};

#endif // WINDOW_H

window.cpp:

代码语言:javascript
复制
#include "window.h"

    Window::Window(QScreen* screen) :
        QWindow(screen)
    {
        setSurfaceType(OpenGLSurface);

        QSurfaceFormat format;
        format.setDepthBufferSize(24);
        format.setMajorVersion(4);
        format.setMinorVersion(3);
        format.setSamples(4);
        format.setProfile(QSurfaceFormat::CoreProfile);
        setFormat(format);
        create();

        m_context = new QOpenGLContext;
        m_context->setFormat(format);
        m_context->create();

        // Make the context current on this window
        m_context->makeCurrent( this );

        // Obtain a functions object and resolve all entry points
        // m_funcs is declared as: QOpenGLFunctions_4_3_Core* m_funcs
        m_funcs = m_context->versionFunctions();
        if ( !m_funcs ) {
            qWarning( "Could not obtain OpenGL versions object" );
            exit( 1 );
        }
        m_funcs->initializeOpenGLFunctions();
    //    m_funcs->glVertexAttribDivisor();
    }

main.cpp:

代码语言:javascript
复制
#include <QCoreApplication>
#include <QGLWidget>

int main(int argc, char *argv[]) {

    QCoreApplication app(argc, argv);
    return app.exec();
}

错误:从'QAbstractOpenGLFunctions*‘到'QOpenGLFunctions_4_3_Core*’-fpermissive的无效转换

EN

回答 1

Stack Overflow用户

发布于 2013-07-15 09:40:34

我在Qt的文档中找到了解决方案。声明应该是

代码语言:javascript
复制
m_funcs = m_context->versionFunctions<QOpenGLFunctions_4_3_Core>();

这样就消除了错误。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17646810

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档