[Qt-interest] Shared data issue

Sajjad dosto.walla at gmail.com
Tue Jul 13 09:27:01 CEST 2010


Hello forum,

I have a class whose data will be shared among several widgets within the
main window. So i have created a singleton of that shared class. I have also
declared several public slots to set  values for those data. The format of
the class is as follows:

*************************************
class SharedWidgetData : public QObject
{
    Q_OBJECT

public:
    SharedWidgetData(  QObject *parent = 0 );

    ~SharedWidgetData();

signals:

    void modelMatrixChanged(const GLdouble*);
    void projectionMatrixChanged(const GLdouble*);
    void inversionMatrixChanged(const GLdouble*);

public slots:

    void setModelViewMatrix(const GLdouble*);
    void setProjectionMatrix(const GLdouble*);
    void setInverseMatrix(const GLdouble*);

    void setSwapFlag(bool);
    void setWorldDrawFlag(bool);

public:

    GLdouble modelViewMatrix[16];
    GLdouble projectionMatrix[16];
    GLdouble invertedMatrix[16];


    GLboolean world_draw;

    GLboolean swapped;

    //contiainer to hold the contents of the xml file
    QMap<int,Cell*>  cellMap;


    XmlStreamReader *dataReader;

};

*************************************


>From the main window i am sending the instance of that singleton shared data
object pointer to all  the widgets that will access and updates its data as
follows:

*************************************

    setupUi(this);

    //create a singleton object of the shared widget data
    Singleton<SharedWidgetData>::init(new SharedWidgetData());

    //send the single shared instance to all  the widgets that will be
accessing
    //the shared data

WorldSpaceViewWidget->setSharedDataInstance(Singleton<SharedWidgetData>::getPtr());

ScreenSpaceViewWidget->setSharedDataInstance(Singleton<SharedWidgetData>::getPtr());

groupBoxCommandView->setSharedDataInstanceGroupBox(Singleton<SharedWidgetData>::getPtr());

*************************************


Now the groupBoxCommandView has been promoted to another class to enable
context menu option with that group box. Inside the context menu have
several actions defined and one of the actions is triggerring a signal that
will call the corresponding slot in the shared widget object. The connection
is established as follows:

************************************

void GroupBoxCommandExtendedBox::createActions()
{
    swapAction = new QAction(tr("&Swap translate/rotate"),this);
    swapAction->setStatusTip(tr("Swap  the glTranslate and the glRotate
command"));
    swapAction->setCheckable(true);


connect(swapAction,SIGNAL(triggered(bool)),pSharedData,SLOT(setSwapFlag(bool)));


    resetAction = new QAction(tr("Reset the command parameters"),this);
    resetAction->setStatusTip(tr("Reset the command parameters to initial
values"));
}


************************************


The program crashes on the above connection. Is that possible to have a
non-checkable context menu and still manage to send a boolean to the slot?

And any idea why it have crashed?

I have put an assertion while initializing the pSharedData, so that it does
not point to NULL. I have done this as follows:

****************************************
void
GroupBoxCommandExtendedBox::setSharedDataInstanceGroupBox(SharedWidgetData
*sharedData)
{
    Q_ASSERT(sharedData != NULL);
    pSharedData = sharedData;
}

****************************************


Is there anything i missed in the process or i have not elaborated enough ?


Please let me know any of you suggestion on this issue.


Regards
Sajjad
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100713/89a0ef55/attachment.html 


More information about the Qt-interest-old mailing list