[Qt-interest] Calling parent Widget slot

Donal O'Connor donaloconnor at gmail.com
Thu Apr 9 16:56:58 CEST 2009


Hi There,

I have a custom widget and in it's constructor I pass a parent widget's
pointer. The parent is also a custom widget (QWidget) with a custom slot.

For exampe:

MyCustomWidget(QWidget * parent )
   : QWidget(parent)
{
}

In the custom child widget, I now want to call the parent's custom slot from
the child. I am doing it this way:

 (static_cast<ParentWidgetType*>(parentWidget()))->setStatus(tr("Update
Status"));

The reason for the cast is I need to access the custom slot I've
implemented.

Now this works fine, until I try and change a member variable in the
setStatus(const QString & statusText) method.
For example:

void ParentWidgetType::setStatus(const QString & statusText)
{
    m_status->setText(statusText);
}

This creates a *segmentation fault*, where as

void ParentWidgetType::setStatus(const QString & statusText)
{
     qDebug() << "Hello";
}

It isn't a case that the m_status isn't created already, it is initialized
in the constructor as:

m_status = new QLabel("No Status");

I also called the slot within the Parent widget and I've no problems.

Forgive me if this is more a C++ problem rather than QT.

Am I missing something obvious?

Regards,
Donal
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090409/06364de5/attachment.html 


More information about the Qt-interest-old mailing list