gpt4 book ai didi

opengl - 在 Qt5.1 和 OpenGL 中从 'QAbstractOpenGLFunctions*' 到 'QOpenGLFunctions_4_3_Core*' 的无效转换

转载 作者:行者123 更新时间:2023-12-02 10:40:49 25 4
gpt4 key购买 nike

我正在通过引用 KDAB's article part one 学习 OpenGL .这是相当新的和有帮助的。但是,我在页面上尝试他的代码时遇到编译错误。

我的Qt工程中有3个文件:main.cpp、window.cpp和window.h。

窗口.h:

#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

窗口.cpp:

#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();
}

主要.cpp:

#include <QCoreApplication>
#include <QGLWidget>

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

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

错误:从“QAbstractOpenGLFunctions*”到“QOpenGLFunctions_4_3_Core*”的无效转换 [-fpermissive]

最佳答案

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

m_funcs = m_context->versionFunctions<QOpenGLFunctions_4_3_Core>();

然后错误被消除。

关于opengl - 在 Qt5.1 和 OpenGL 中从 'QAbstractOpenGLFunctions*' 到 'QOpenGLFunctions_4_3_Core*' 的无效转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17646810/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com