[Interest] Usage of QAbstractOpenGLFunctions and derived classes

Sean Harmer sean.harmer at kdab.com
Tue Dec 17 11:53:33 CET 2013


On Tuesday 17 December 2013 01:21:14 Thiago Macieira wrote:
> On terça-feira, 17 de dezembro de 2013 09:49:48, Yves Bailly wrote:
> > (1)
> > When I try to build this program, I get a link error:
> > gl_widget.obj : error LNK2019: symbole externe non résolu "protected: bool
> > __cdecl QAbstractOpenGLFunctions::isInitialized(void)const "
> > (?isInitialized at QAbstractOpenGLFunctions@@IEBA_NXZ) référencé dans la
> > fonction "protected: virtual void __cdecl Gl_Widget::initializeGL(void)"
> > (?initializeGL at Gl_Widget@@MEAAXXZ)
> > 
> > ...which basically says the external symbol
> > QAbstractOpenGLFunctions::isInitialized() could not be resolved.
> > If I remove the "if" line, thus not calling isInitialized(), everything
> > works fine. I even tried to force name resolution with "if (not
> > this->QOpenGLFunctions_3_3_Core::isInitialized())", but no luck.
> > 
> > Any idea about what can go wrong?
> 
> Yes: you're calling a function that is not public. Stop calling
> isInitialized().
> 
> > To alleviate those points, I tried something like this (with various
> > variations and more sanity checks):
> > 
> > class My_Class: public
> > Some_Other_Super, protected QOpenGLFunctions_3_3_Core {
> > 
> >    void some_init_method()
> >    {
> >    
> >      QOpenGLContext* ctx = QOpenGLContext::currentContext();
> >      QOpenGLFunctions_3_3_Core* funcs =
> > 
> > ctx->versionFunctions<QOpenGLFunctions_3_3_Core>();
> > dynamic_cast<QOpenGLFunctions_3_3_Core&>(*this) = *funcs;
> > 
> >    }
> > 
> > }
> 
> Why are you trying to initialize like that? You should simply call
> initializeOpenGLFunctions().

Yes, what Thiago said is correct. Don't be shy about calling this function as 
it's basically a no-op if it has already been called before.

If you're planning on using the functions object in more than one class you 
may be better off obtaining a pointer to it from the 
QOpenGLContext::versionFunctions<QOpenGLFunctions_3_3_Core>() function rather 
than sub-classing. The object is owned by the context and is shared which is 
less overhead than having multiple classes of your own all of which subclass.

Cheers,

Sean

ps I'm looking to add support for OpenGL 4.4 but this requires rewriting the 
spec parser used to generate these classes as Khronos has now switched from 
the legacy .spec files to an XML format. Also I need a 4.4 capable GPU... ;)

--
Dr Sean Harmer | sean.harmer at kdab.com | Managing Director UK
Klarälvdalens Datakonsult AB, a KDAB Group company
Tel. Sweden (HQ) +46-563-540090, USA +1-866-777-KDAB(5322)
KDAB - Qt Experts - Platform-independent software solutions



More information about the Interest mailing list