无法使用QGLWidget编译Qt

时间:2016-01-03 20:21:23

标签: c++ qt maya vtable qglwidget

我正在用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();
}

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

1 个答案:

答案 0 :(得分:0)

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