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. Strange OpenGL initialization error in Linux
Qt 6.12 LTS is out! See what's new in the release blog

Strange OpenGL initialization error in Linux

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 2.7k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    I recently inherited a QT application for a project I'm working with that uses an OpenGL widget. The code worked as expected under Windows and Mac, but under Linux the OpenGL widget displayed nothing but garbage from the framebuffer. There were no errors from OpenGL, and nothing in the code looked like it should be causing such a problem. I tried adding calls to makeCurrent() in several places, and a few other things. Ultimately the only thing I could find that fixed the problem was adding this line of code at the beginning of the OpenGL widget's constructor:
    @ setContext( new QGLContext( QGLFormat(), this ) ); @

    With that line of code in place, everything worked under Linux just as under Windows or Mac. I assume this means there was some problem with initializing the OpenGL context under Linux, but I'm totally at a loss as to what could be causing it. Any thoughts would be appreciated.

    Here's the constructor in it's entirety:
    @OpenGLWidget::OpenGLWidget(MainWindow *main_window,
    QWidget *parent,
    const char *name) : QGLWidget(parent, 0, 0), main_window_(main_window) {

    setContext( new QGLContext( QGLFormat(), this ) );

    setMouseTracking(true);
    setAcceptDrops(true);
    setFocusPolicy(Qt::StrongFocus);

    zoom = 2.0f;
    z_angle = 0.0f;

    // initialize camera
    camera_ = new OpenGLCamera();
    next_target_ = camera_->getTarget();
    FAHVector3 eye_dest;
    eye_dest.set(next_target_).add(FAHVector3::make(150zoomsin(z_angle),150zoomcos(z_angle),150*zoom));
    camera_->setEye(eye_dest.x, eye_dest.y, eye_dest.z);

    hasClicked = false;
    wireframeMode = true;

    connect(&advance_camera_timer_, SIGNAL(timeout()), this, SLOT(advanceCameraToTarget()));

    setFocus();
    }@

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      I can't tell from what you have posted above. Could you extract a small compilable example that reproduces the problem please?

      What GPU card and drivers are you using?

      It's odd because creating a QGLContext with a default QGLFormat is essentially all that QGLWidget does anyway.

      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