Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QPainter assertion error
QtWS25 Last Chance

QPainter assertion error

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 3.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mehoggan
    wrote on last edited by
    #1

    [EDIT: adjusted the thread topic, Volker]

    I have an application that builds just fine. However when I run it from within Qt Creator in both debug and release mode I get a run time error.

    The Debug Error! reads

    Program:
    ..._QPainter\QtGL_QPainter-build-desktop\debug\QtGL_QPainter.exe
    Module: 4.7.3
    File: global\qglobal.cpp
    Line: 2262

    ASSERT: "d" in file
    c:\iwmake\build_vs2008_opensource___________________padding____________
    ______\include\qtcore../../src/corelib/tools/qscopedpointer.h, line 112

    Going into debug mode my program is crashing on line number 92 of vowelcube.cpp. Please see code below, the line where the debuger shows the crash, will be between astricks.

    The dubug message box shows,
    The inferior stopped because it triggered an exception.

    Stopped in thread 0 by: Exception at 0x74a02745, code: 0xc0000005: read access
    violation at 0x0, flags=0x0.

    main.cpp
    @#include <QtGui/QApplication>
    #include "vowelcube.h"

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    VowelCube w;
    w.show();

    return a.exec&#40;&#41;;
    

    }@

    vowelcube.h
    @#ifndef VOWELCUBE_H
    #define VOWELCUBE_H

    #include <QtOpenGL>
    #include <QWidget>

    class VowelCube : public QGLWidget
    {
    Q_OBJECT
    public:
    VowelCube(QWidget *parent = 0);
    ~VowelCube();

    protected:
    void paintEvent(QPaintEvent *event);
    //void mousePressEvent(QMouseEvent *event);
    //void mouseMoveEvent(QMouseEvent *event);
    void wheelEvent(QWheelEvent *event);

    private:
    void createGradient();
    void createGLObject();
    void drawBackground(QPainter *painter);
    void drawCube();
    void drawLegend(QPainter *painter);

    GLuint glObject;
    QRadialGradient gradient;
    GLfloat rotationX;
    GLfloat rotationY;
    GLfloat rotationZ;
    GLfloat scaling;
    QPoint lastPos;
    

    };

    #endif // VOWELCUBE_H@
    vowelcube.cpp
    @#include "vowelcube.h"
    #include <cmath>

    VowelCube::VowelCube(QWidget *parent) :
    QGLWidget(parent)
    {
    setFormat(QGLFormat(QGL::SampleBuffers));

    rotationX = -38.0;
    rotationY = -58.0;
    rotationZ = 0.0;
    scaling = 1.0;
    
    createGradient();
    createGLObject();
    

    }

    void VowelCube::createGradient()
    {
    gradient.setCoordinateMode(QGradient::ObjectBoundingMode);
    gradient.setCenter(0.45, 0.50);
    gradient.setFocalPoint(0.40, 0.45);
    gradient.setColorAt(0.0, QColor(106, 146, 182));
    gradient.setColorAt(0.4, QColor(81, 113, 150));
    gradient.setColorAt(0.8, QColor(16, 56, 121));
    }

    void VowelCube::createGLObject()
    {
    makeCurrent();

    glShadeModel(GL_FLAT);
    
    glObject = glGenLists(1);
    glNewList(glObject, GL_COMPILE);
    qglColor(QColor(255, 239, 191));
    glLineWidth(1.0);
    
    glBegin(GL_QUADS);
        glVertex3f(+1.0f, +1.0f, -1.0f);
        glVertex3f(-1.0f, +1.0f, -1.0f);
        glVertex3f(-1.0f, -1.0f, -1.0f);
        glVertex3f(+1.0f, -1.0f, -1.0f);
    glEnd();
    
    glBegin(GL_QUADS);
        glVertex3f(+1.0f, +1.0f, +1.0f);
        glVertex3f(+1.0f, +1.0f, -1.0f);
        glVertex3f(+1.0f, -1.0f, -1.0f);
        glVertex3f(+1.0f, -1.0f, +1.0f);
    glEnd();
    
    glBegin(GL_QUADS);
        glVertex3f(-1.0f, +1.0f, +1.0f);
        glVertex3f(+1.0f, +1.0f, +1.0f);
        glVertex3f(+1.0f, -1.0f, +1.0f);
        glVertex3f(-1.0f, -1.0f, +1.0f);
    glEnd();
    
    glBegin(GL_QUADS);
        glVertex3f(-1.0f, +1.0f, -1.0f);
        glVertex3f(-1.0f, -1.0f, -1.0f);
        glVertex3f(-1.0f, -1.0f, +1.0f);
        glVertex3f(-1.0f, +1.0f, +1.0f);
    glEnd();
    
    glBegin(GL_QUADS);
        glVertex3f(-1.0f, +1.0f, +1.0f);
        glVertex3f(+1.0f, +1.0f, +1.0f);
        glVertex3f(+1.0f, +1.0f, -1.0f);
        glVertex3f(-1.0f, +1.0f, -1.0f);
    glEnd();
    
    glBegin(GL_QUADS);
        glVertex3f(-1.0f, -1.0f, +1.0f);
        glVertex3f(+1.0f, -1.0f, +1.0f);
        glVertex3f(+1.0f, -1.0f, -1.0f);
        glVertex3f(-1.0f, -1.0f, -1.0f);
    glEnd();
    
    glEndList();
    

    }

    VowelCube::~VowelCube()
    {
    makeCurrent();
    glDeleteLists(glObject, 1);
    }

    void VowelCube::paintEvent(QPaintEvent * /* event */)
    {
    QPainter painter(this);
    drawBackground(&painter);
    drawCube();
    drawLegend(&painter);
    }
    ...--
    @

    What is causing this crash?

    Matthew Hoggan
    http://matthewh.me
    “It’s not wise to violate rules until you know how to observe them.” (t.s. eliot)

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jeffreyholmes
      wrote on last edited by
      #2

      I am having the same problem, no answer to this?
      This program is taken out of the book "C++ Gui Programming with QT 4"

      1 Reply Last reply
      0
      • Y Offline
        Y Offline
        Ymalaika
        wrote on last edited by
        #3

        Yeah, unfortunately this example is broken in later versions of Qt. One problem is that QGLWidget::setFormat has been removed since around 4.7 or so. If I comment out that line in the constructor, which turns on anti-aliasing, it compiles and runs for me in 4.8.5. The 3D rendering is missing, though. It's a useful example and I hope the authors of the book keep it or something similar in the updated version of the book.

        Meanwhile, if you look in the OpenGL examples that come with Qt 4.8 and 5.1, there are projects called overpainting and hellogl_es2 that also demonstrate combining 3D opengl drawing with 2D qpainter calls. They are perhaps not as well explained as the book example, but hopefully will be informative to you.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved