gpt4 book ai didi

c++ - 无法使用 QGLWidget 编译 Qt

转载 作者:太空宇宙 更新时间:2023-11-04 13:22:31 25 4
gpt4 key购买 nike

我正在用 C++ 编写 Maya 插件。然而,每当我想使用 QGLWidget 时,我都会收到大量 vtable 错误:

Undefined symbols for architecture x86_64:
"QGLWidget::paintEvent(QPaintEvent*)", referenced from:
vtable for GLWidget in myOpenGLWindowClass.o
"QGLWidget::qt_metacall(QMetaObject::Call, int, void**)", referenced from:
vtable for GLWidget in myOpenGLWindowClass.o
"QGLWidget::qt_metacast(char const*)", referenced from:
vtable for GLWidget in myOpenGLWindowClass.o
"QGLWidget::resizeEvent(QResizeEvent*)", referenced from:
vtable for GLWidget in myOpenGLWindowClass.o
"QGLWidget::paintOverlayGL()", referenced from:
vtable for GLWidget in myOpenGLWindowClass.o
"QGLWidget::resizeOverlayGL(int, int)", referenced from:
vtable for GLWidget in myOpenGLWindowClass.o
"QGLWidget::updateOverlayGL()", referenced from:
vtable for GLWidget in myOpenGLWindowClass.
...

代码如下:

#include <QtGui/QApplication>
#include <QGLWidget>

class GLWidget :public QGLWidget
{

public:
GLWidget(QWidget *parent = 0);
virtual ~GLWidget(){};
protected:
virtual void initializeGL();
virtual void resizeGL( int width, int height );
virtual void paintGL();

};

GLWidget::GLWidget(QWidget *parent) : QGLWidget(parent)
{

}

void GLWidget::initializeGL() {
glDisable(GL_TEXTURE_2D);
glDisable(GL_DEPTH_TEST);
glDisable(GL_COLOR_MATERIAL);
glEnable(GL_BLEND);
glEnable(GL_POLYGON_SMOOTH);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glClearColor(0, 0, 0, 0);
}

void GLWidget::resizeGL(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

void GLWidget::paintGL()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1,0,0);
glBegin(GL_POLYGON);
glVertex2f(0,0);
glVertex2f(100,500);
glVertex2f(500,100);
glEnd();
}

是否有我需要在我的编译中添加的库或其他任何错误?

最佳答案

我需要在编译中添加 QtOpenGL 框架。

关于c++ - 无法使用 QGLWidget 编译 Qt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34581173/

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