Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to use updateGL method qith QGLView
Qt 6.12 LTS is out! See what's new in the release blog

How to use updateGL method qith QGLView

Scheduled Pinned Locked Moved General and Desktop
9 Posts 2 Posters 4.9k Views 1 Watching
  • 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.
  • S Offline
    S Offline
    sunil.nair
    wrote on last edited by
    #1

    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/

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sunil.nair
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Just call update, that should be enough

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • S Offline
            S Offline
            sunil.nair
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

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

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • S Offline
                S Offline
                sunil.nair
                wrote on last edited by
                #7

                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?

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  "QGLView::update()":https://qt.gitorious.org/qt/qt3d/source/8a9723d7420829a2ba0141a9f7d8dc8cd11d8331:src/threed/viewing/qglview.h#L108

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    sunil.nair
                    wrote on last edited by
                    #9

                    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);
                    

                    }

                    @

                    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
                    • Unsolved