PDA

View Full Version : QGLWidget - how to share context



thinkabit
28th April 2011, 15:12
hi all, sorry, still pretty new to qt ...

can't find any example on how to share the context between two QGLWidgets.
It's mentioned everywhere, that this should be possible, but i can't get it to work.

what i've tried so far:

this gives me an "invalid conversion from 'const QGLContext*' to 'QGLContext*'" in the hw=... line


Widget::Widget(QWidget *parent) : QWidget(parent)
{
glw = new GLWidget(this);
hw = new HiddenWidget(glw->context(), this, glw);
...
}

HiddenWidget::HiddenWidget(QGLContext *contxt, QWidget *parent, QGLWidget *shared) : QGLWidget(contxt, parent, shared)
{
...
}

GLWidget::GLWidget(QWidget *parent) : QGLWidget(parent)
{
...
}


i've also tried something like


QGLFormat format;
QGLContext *contxt;
contxt=new QGLContext(format);

in the Widget class constructor and pass that to another constructor for GLWidget and to HiddenWidget, but that didn't work either, and i wouldn't know where and when to assign the context to whom ...


glw = new GLWidget(contxt, this, NULL);
hw = new HiddenWidget(contxt, this, glw);


GLWidget::GLWidget(QGLContext *contxt, QWidget *parent, QGLWidget *shared) : QGLWidget(contxt, parent, shared)
{
}


thanks for help,

oliver

high_flyer
29th April 2011, 17:47
As far as I understand the docs (didn't do it my self) you need only to give the other QGLWidget pointer with which this one will share the context, so you don't need to explicity give QGLConext parameter.
But rather so:


Widget::Widget(QWidget *parent) : QWidget(parent)
{
glw = new GLWidget(this);
hw = new HiddenWidget(/*glw->context(),*/ this, glw);
...
}

GLWidget::GLWidget( QWidget *parent, QGLWidget *shared) : QGLWidget(contxt, parent, shared)
{
}


by giving a valid pointer to another QGLWidget, you will cause context sharing between them.