How to use updateGL method qith QGLView



  • UpdateGL method is found in QGLWidget class. Since, QGLView is an extension of QGLWidget, it should contain a method to update. I need to put my update code somewhere. One option is to use the QTimer but is there any other possibility? Some reference on this question is here.

    http://qt-project.org/forums/viewthread/38167/


  • Lifetime Qt Champion

    Hi,

    I've corrected that, but anyway, if you plan to use Qt3D you should rather take a look at the dev branch which is the future of Qt3D



  • Hello, thanks for the reply. Is there any way to explicitly call the paintgl method in QT?


  • Lifetime Qt Champion

    Just call update, that should be enough



  • Is the update() method present in the QGLView class. Because, whenever I write update, I get an error saying identifier not found


  • Lifetime Qt Champion

    It's the only slot of QGLView. What version of Qt3D are you using ?



  • I am using qt3d for QT5.3.2.
    https://qt.gitorious.org/qt/qt3d/source/8a9723d7420829a2ba0141a9f7d8dc8cd11d8331:

    It worked for me. My QGLview was ingheriting the QWindow class earlier. I changed it to inherit the Qwidget class instead and I could find the update() function.
    However, when you say QGLview slot. I tried it without the QWidget class and it did not work for me. But, with Qwidget it works as you mentioned.

    Thank you for your support. I hope you could clarify on the update slot for QGLview without inheriting the QWidget?


  • Lifetime Qt Champion



  • I tried this way. But , I am still getting the same error.
    C:\Qt\qt-qt3d\tutorials\qt3d\cube4\cubeview.cpp:128: error: undefined reference to `CubeView::update()'

    cubeview.h
    @
    #ifndef CUBEVIEW_H
    #define CUBEVIEW_H

    #include "qglview.h"
    #include "qgltexture2d.h"

    QT_BEGIN_NAMESPACE
    class QGLSceneNode;
    QT_END_NAMESPACE

    //! [1]
    class CubeView : public QGLView
    {
    //! [1]
    Q_OBJECT
    public:

    CubeView(QWindow *parent = 0);
    ~CubeView();
    

    public slots:
    void update_action();
    public Q_SLOTS:
    void update();

    protected:
    void paintGL(QGLPainter *painter);

    //! [2]
    

    private:
    QGLSceneNode *cube;
    QGLSceneNode cursor;
    QGLTexture2D logo;
    QGLTexture2D
    texture;
    QGLTexture2D handcursor;

    };
    //! [2]

    #endif
    @

    cubeview.cpp
    @
    #include "cubeview.h"
    #include "qglbuilder.h"
    #include "qglcube.h"
    #include "haptics.h"
    #include <iostream>
    #include <QThread>
    #include <QTimer>
    #include <QDebug>
    #include "qglpainter.h"
    #include "qgraphicstranslation3d.h"

    //! [1] constructor, initialize the cube, cursor and camera
    CubeView::CubeView(QWindow *parent)
    {
    //! [1]
    QGLBuilder builder1;
    builder1 << QGL::Faceted;
    builder1 << QGLCube(2);
    cube = builder1.finalizedSceneNode();

    QGLBuilder cursor_builder;
    cursor_builder <<QGL::Faceted;
    cursor_builder <<QGLCube(0.5);
    cursor=cursor_builder.finalizedSceneNode();
    
    //camera setup
    camera()->setFieldOfView(35);
    camera()->setNearPlane(1);
    camera()->setFarPlane(15);
    

    //! [2] set texture for cube and cursor
    logo.setImage(QImage(QLatin1String(":/blackcircle.jpg")));
    handcursor.setImage(QImage(QLatin1String(":/hand.jpg")));

    //timer to call the update action slot
    QTimer *timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(update_action()));
    timer->start(50);
    

    }
    //! [2] update the cursor based on the haptic position
    void CubeView::update_action()
    {
    QVector3D *p2=new QVector3D(1,1,1--);
    cursor->setPosition(*p2);
    update();
    }

    CubeView::~CubeView()
    {
    logo.cleanupResources();
    delete cube;
    delete cursor;
    }
    //! [3]
    void CubeView::paintGL(QGLPainter *painter)
    {
    painter->setStandardEffect(QGL::LitDecalTexture2D);
    painter->setFaceColor(QGL::AllFaces, QColor(170, 202, 0));
    logo.bind();

    cube->draw(painter);
    handcursor.bind();
    cursor->draw(painter);
    

    }

    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.