You are not logged in.

Snag

Unregistered

1

Wednesday, December 29th 2004, 5:29pm

Parent to child signal

Where should I put the connection if I want the parent widget to send data to its child? The other way round, I always declared QObject::connect in the parent code. Now, if i write the connection in the child widget this way:
QObject::connect(this->parentWidget(),SIGNAL(takeTheTitle(QString,int)),this,SLOT(gotTitle(QString,int)));

with "this" being the child widget, I receive the following output:
Cannot connect (null)::takeTheTitle(QString,int) to teamList::gotTitle(QString,int)

While
QObject::connect(this,SIGNAL(takeTheTitle(QString,int)),teams,SLOT(gotTitle(QString,int)));

with "this" being the parent widget and teams the child one, simply does nothing.

Aargh!
Snag.

  • "wysota" is male

Posts: 4,276

Location: Warsaw, POLAND

  • Send private message

2

Wednesday, December 29th 2004, 5:50pm

RE: Parent to child signal

Source code

1
connect((parent_widget_class_name*)parentWidget(),SIGNAL(takeTheTitle(QString,int)),this,SLOT(gotTitle(QString,int)));


Remember that parentWidget returns a generic class and you have to cast it to a proper one. Please also note that using parent() instead of parentWidget() is advised, as the parent may be a subclass of QObject but not QWidget.