QGLWidget different behavior on windows and linux
-
Hello,
First of all I'm using qt 4.7.2 on my Linux kubuntu, and qt 4.7.4 on my Windows vista.
I'm using a custom context class inheriting from QGLContext.The problem:
When I use the QGLWidget constructor taking a QGLContext under Windows all works fine.
But under Linux the GLWidget does not seems to take the good format from my context (it has a different visual configuration ), so I have to set the format and the context manually in my custom QGLWidget constructor.@ QGLContextAdapter * create_context()
{
return new QGLContextAdapter(
vglc::GLContext::Config(
vglc::GLContext::Config::MinVersion(4, 1),
vglc::GLContext::Config::LIGHT_R8G8B8,
#ifdef NDEBUG
vglc::GLContext::Config::DEBUG_OFF,
#else
vglc::GLContext::Config::DEBUG_ON,
#endif
vglc::GLContext::Config::STRICT_CORE
)
);
}GLWidget::GLWidget( QWidget * parent )
: QGLWidget(
#if defined( VIRTREV_WIN32 ) // under windows it's not possible to set context later
create_context(),
#endif
parent
),
ui(new Ui::GLWidget),
log_dialog_(NULL)
{
ui->setupUi(this);#if defined( VIRTREV_LINUX ) // under linux if we pass the context to QGLWidget constructor, QGLWidget will not use the good format
QGLContextAdapter * context = create_context();
setFormat( context->format() );
context->setDevice( this );
setContext( context );
#endif
}@Is this a bug which has been solved in 4.7.4 or is this not a bug ?
-
Reading qt source code (qgl_x11.cpp) I guess I understand why there is the problem.
The visual used to create the window is only set in qglcontext::choosecontext and since this a private data of qglcontext (d->vi), my custom QGLContext (which redefined choosecontext) as no way to setup the visual. So it use a 0 visual which is CopyFromParent.
The setformat; is a bit of a trick because it let a temporary QGLContext set the visual.
I guess one solution would be to call choosevisual in qglcontext::create to initialize the visual instead of doing it in choosecontext.