Results 1 to 2 of 2

Thread: QGLWidget - how to share context

  1. #1
    Join Date
    Apr 2011
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default QGLWidget - how to share context

    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

    Qt Code:
    1. Widget::Widget(QWidget *parent) : QWidget(parent)
    2. {
    3. glw = new GLWidget(this);
    4. hw = new HiddenWidget(glw->context(), this, glw);
    5. ...
    6. }
    7.  
    8. HiddenWidget::HiddenWidget(QGLContext *contxt, QWidget *parent, QGLWidget *shared) : QGLWidget(contxt, parent, shared)
    9. {
    10. ...
    11. }
    12.  
    13. GLWidget::GLWidget(QWidget *parent) : QGLWidget(parent)
    14. {
    15. ...
    16. }
    To copy to clipboard, switch view to plain text mode 


    i've also tried something like

    Qt Code:
    1. QGLFormat format;
    2. QGLContext *contxt;
    3. contxt=new QGLContext(format);
    To copy to clipboard, switch view to plain text mode 

    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 ...

    Qt Code:
    1. glw = new GLWidget(contxt, this, NULL);
    2. hw = new HiddenWidget(contxt, this, glw);
    3.  
    4.  
    5. GLWidget::GLWidget(QGLContext *contxt, QWidget *parent, QGLWidget *shared) : QGLWidget(contxt, parent, shared)
    6. {
    7. }
    To copy to clipboard, switch view to plain text mode 

    thanks for help,

    oliver
    Last edited by high_flyer; 29th April 2011 at 17:18. Reason: code tags

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QGLWidget - how to share context

    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:
    Qt Code:
    1. Widget::Widget(QWidget *parent) : QWidget(parent)
    2. {
    3. glw = new GLWidget(this);
    4. hw = new HiddenWidget(/*glw->context(),*/ this, glw);
    5. ...
    6. }
    7.  
    8. GLWidget::GLWidget( QWidget *parent, QGLWidget *shared) : QGLWidget(contxt, parent, shared)
    9. {
    10. }
    To copy to clipboard, switch view to plain text mode 

    by giving a valid pointer to another QGLWidget, you will cause context sharing between them.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. How to render context of QGLWidget, outside of the window
    By KnufflPuffl in forum Qt Programming
    Replies: 1
    Last Post: 28th December 2010, 22:41
  2. QGLWidget overlay context
    By mckinnon in forum Qt Programming
    Replies: 0
    Last Post: 22nd December 2010, 09:17
  3. Replies: 1
    Last Post: 14th November 2008, 03:59
  4. Replies: 0
    Last Post: 7th April 2008, 15:27

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.