Important: Please read the Qt Code of Conduct -

How do I bind a texture in QtGui OpenGL

  • Hello all,

    I posted this to the games area, but it's really more broad than that, so I'd ask this here. I’m newish to OpenGL, but not C++. I am wanting to learn more about OpenGL. I was able to follow along with the triangle example for QtGui’s OpenGL stuff (found at However, I cannot figure out how to add a texture to OpenGL. I know how to do it via OpenGL in general and in Qt 4.8 you could use the bindTexture() function of a QGLWidget. However, since with Qt 5.0 they recommend you don’t use that for new programs, I’d like to avoid using it. My hope is to be able to do something like the qt cube example (available here: but with using the QOpenGL classes instead of QGL classes. Can anyone help me with the texture binding information so I can use that instead? Thanks ahead of time.

  • Hi,

    I'm trying to do the same thing (using textures with the triangle in OpenGLWindow).
    Do you have solve your problem ?


  • Well, no, I didn't solve my problem. I found this article and it has a method for doing it:

    I just decided to use OpenGL outside of Qt since they broke it a bit for a while. I use GLEW with SFML if you're interested in what I did. Hope that article helps you, the texture code is in the zip file attached to the article.

  • Hi,

    Thanks for you fast answer.

    I just tried to use the Texture class found in zip, but I still have the same problem. I obtain a SIGSEV when I call the glDrawArrays function.

    I can't launch the terrain tesselation program, because it requires OpenGL 4.0 and I only have 3.0 on this computer (Intel HD with Ivy bridge).

    I look this link too:
    And I have the same problem.

    I will do more investigation.

  • Hi,

    In fact, I should stop work on OpenGL the evening.
    I just forget to pass the texCoord parameter ...

    This code works:

    It uses QGLContext::bindImage() with a QImage().

    Hope, it can help someone.

Log in to reply