[Qt-interest] multiple glwidget interaction

John McClurkin jwm at nei.nih.gov
Wed Jul 7 20:29:29 CEST 2010


Sajjad wrote:
> Hello John,
> 
> I am having some interesting behavior now.
> 
> If i instantiate the SharedWidgetData from the main it does not crash , 
> but it crashes if it is instantiated inside the constructor of the 
> TransformationMainWindow class.  I need to elaborate the design i done 
> so far:
> 
> 1. I have created a main window using designer and created two widgets. 
> Both the widgets are promoted to corresponding gl widgets.
> 
> 2. Declare another class named  TransformationMainWindow with  the 
> following hierarchy:
> 
> ***********************************************************
> 
> class TransformationMainWindow : public QMainWindow : private 
> Ui::TransformationWindow
> {
> 
> }
> 
> ***********************************************************
> 
> 
> 3. Inside the constructor of TransformationMainWindow i try to 
> instantiate the SharedWidgetData class and it crashes. So i am attaching 
> the class declaration and definition. You might see that i am stil missing.
> 
> 
> Thanks for the hints so far!

I don't see anything in your code. You might try using a debugger to 
single step into your TransformationMainWindow constructor to see where 
it crashes. You might also try instantiating the SharedWidgetData object 
  outside the TransformationMainWindow constructor.

> 
> 
> 
> Sajjad
> 
> On Wed, Jul 7, 2010 at 5:15 PM, John McClurkin <jwm at nei.nih.gov 
> <mailto:jwm at nei.nih.gov>> wrote:
> 
>     Sajjad wrote:
>      > Hello John,
>      >
>      > I have declared a SharedWidgetData class that contains all  the
>     matrices
>      > that need to be shared between 2 gl widgets.
>      >
>      > Then i created a singleton class and instantiate one instance of the
>      > SharedWidgetData  in the constructor of the top level window
>     constructor
>      > as follows:
>      >
>      >
>      >
>     ******************************************************************************
>      > Singleton<SharedWidgetData>::init(new SharedWidgetData());
>      >
>      >
>     ******************************************************************************
>      >
>      > Then i send the pointers of the newly instantiated object to both the
>      > widgets so that both the widgets can access and update the
>     matrices as
>      > necessary.
>      >
>      > But the program crashes and while debugging it i found that the
>     program
>      > gives a segmentation fault in the above line.  Singleton class is
>      > full-proof i believe since it has been used in another API and it has
>      > been quite functional so far.
>      >
>      >
>      >
>      > Any hint to track  the issue?
> 
>     The Singleton class may be fool proof and may have been used
>     successfully elsewhere, but it may be giving you problems in your
>     instance. Try just creating an instance of your SharedWidgetData class;
> 
>     SharedWidgetData *p = new SharedWidgetData();
> 
>     If this also crashes, you have a problem in your constructor. If not
>     there must be a problem with the Singleton implementation.
>      >
>      >
>      > Regards
>      > Sajjad
>      >
>      >
>      >
>      >
>      >
>      > On Tue, Jul 6, 2010 at 8:54 PM, John McClurkin <jwm at nei.nih.gov
>     <mailto:jwm at nei.nih.gov>
>      > <mailto:jwm at nei.nih.gov <mailto:jwm at nei.nih.gov>>> wrote:
>      >
>      >     Sajjad wrote:
>      >      > Hello forum,
>      >      >
>      >      > I have two separate classes inherited from QGLWidget and
>     both  the
>      >      > classes need to share and update the projection ,
>     modelview and
>      >     inverse
>      >      > matrices . These matrices are defines as follows:
>      >      >
>      >      > I get  the modelview matrix by
>      >      >
>      >      > glGetDoublev(GL_MODELVIEW_MATRIX, modelview); And that
>     modelview
>      >     matrix
>      >      > will be shared and updated by both the QGLWidget subclasses. I
>      >     need to
>      >      > have the following matrices declared, but not sure where to
>      >     declare them.
>      >      >
>      >      > GLdouble modelview[16]
>      >      > GLdouble projection[16]
>      >      > GLdouble inverse[16]
>      >      >
>      >      >
>      >      > I have declared the above matrices in one of the widget
>     and i need to
>      >      > pass the contents of these matrices to another gl widget. Do i
>      >     have to
>      >      > declare another three arrays in that widget as well?
>      >      >
>      >      >
>      >      > I also need to set several signal and slots, like when
>     ever the
>      >     any of
>      >      > the matrices changes the matrices will be passed with  the
>      >     corresponding
>      >      > slots. The slots may be of the same widget or the other
>     widget.
>      >      >
>      >      >
>      >      >
>      >     I would define a class containing the three arrays with
>     functions to get
>      >     and set their values and signals that could be emitted by those
>      >     functions whenever the values were accessed. Then instantiate
>     just one
>      >     instance of that class.
>      >     _______________________________________________
>      >     Qt-interest mailing list
>      >     Qt-interest at trolltech.com <mailto:Qt-interest at trolltech.com>
>     <mailto:Qt-interest at trolltech.com <mailto:Qt-interest at trolltech..com>>
>      >     http://lists.trolltech.com/mailman/listinfo/qt-interest
>      >
>      >
>     _______________________________________________
>     Qt-interest mailing list
>     Qt-interest at trolltech.com <mailto:Qt-interest at trolltech.com>
>     http://lists.trolltech.com/mailman/listinfo/qt-interest
> 
> 



More information about the Qt-interest-old mailing list