Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8936391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:12:23+00:00 2026-06-15T10:12:23+00:00

I’m making a simple triangle in OpenGL with Qt4, and it works fine, until

  • 0

I’m making a simple triangle in OpenGL with Qt4, and it works fine, until I use set format to enable multisampling. Here is my code:

#include <QApplication>
#include <QtOpenGL>
// gl window class
class GLWindow : public QGLWidget
{
public:
    GLWindow(QWidget *parent = nullptr)
        : QGLWidget(parent){}
protected:
    // ALL THE FOLLOWING FUNCTIONS ARE OVERRIDDEN FROM QGLWIDGET 
    void initializeGL()
    {
        QGLFormat newFormat = this->format();
        newFormat.setSampleBuffers(true);
        newFormat.setSamples(16);
        this->setFormat(newFormat);
    }
    void resizeGL(int w, int h)
    {
        glViewport(0, 0, w, h);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glOrtho(-1, 1, -1, 1, -1, 1);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
    }
    void paintGL()
    {
        glClear(GL_COLOR_BUFFER_BIT);
        glBegin(GL_TRIANGLES);
            glColor3f(1, 0, 0);
            glVertex2f(0, 1);
            glColor3f(0, 1, 0);
            glVertex2f(1, -1);
            glColor3f(0, 0, 1);
            glVertex2f(-1, -1);
        glEnd();
    }
};
// main function
int main(int argc, char **argv)
{
    QApplication app(argc, argv);
    GLWindow window;
    window.resize(640, 480);
    window.show();
    return app.exec();
}

Before I added the format stuff in “initlializeGL”, it worked fine (obviously except no multisampling).

Then, I add the format stuff and the window does not close. And when I say this I mean that it will not close when I press the “X” button on the top right corner, or it will not even close when I make a call to the window’s “close()” function.

Furthermore, It makes a call to “closeEvent()” when you press the “X” button (I checked), but nothing actually closes. I tried making a call to “close()” inside my overridden “closeEvent()” function, but it did nothing.

Once again, I remove the code in “initializeGL()”, and then it closes fine. So, I try to move the code I have in “initializeGL()” into the constructor. The multisampling works, and it closes when I press “X”. Great! Except I get this after the window closes:

enter image description here

So that is that. In a nutshell:

  • Everything works fine when there is no “setFormat()” related code in “initializeGL()”.
  • When I do put my “setFormat()” related code in “initializeGL()”, the window doesn’t close.
  • When I put my “setFormat()” related code in the constructor, I get the weird error shown in the above image when the window is closed;

So how to I get the window to close, while keeping multisampling enabled and without getting some dumb error after the window is closed?

EDIT: Here is the text in my .pro file

QT += core
QT += gui
QT += opengl

SOURCES += \
    main.cpp
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T10:12:24+00:00Added an answer on June 15, 2026 at 10:12 am

    You shouldn’t call setFormat from initializeGL, as it triggers a call to initializeGL itself. And since QGLWidget::setFormat is obsolete in Qt 4.8, you shouldn’t use it at all.

    So, first try calling setFormat from the constructor, then, if it doesn’t work (or even if it works), try passing the format to the constructor of QGLWidget from main().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a simple page using Google Maps API 3. My first. One marker
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I want use html5's new tag to play a wav file (currently only supported
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Seemingly simple, but I cannot find anything relevant on the web. What is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.