Qt / C ++: identificación del widget padre en el controlador de eventos (señal)

I'm building a Qt app. In the event handler I want to access the widget that fired the event.

You can do this in the event filter method by casting the QObject parameter:

bool MainWindow::eventFilter(QObject *obj, QEvent *event)
{
    MyWidget* widget= static_cast<MyWidget*>(obj);
    ...
}

But how can I do that inside a signal method? For example, a listview onclick signal:

void MainWindow::listView_Click(QModelIndex index)
{
     QListView* view = // ????
}

Gracias

preguntado el 10 de marzo de 12 a las 16:03

2 Respuestas

Trata QObject :: remitente ().

void MainWindow::listView_Click(QModelIndex index)
{
    QListView* view = qobject_cast<QListView* >(sender());
}

respondido 10 mar '12, 16:03

Thank you too. Very fast response, and exactly what I need. - Alex

The object that sent a signal is available with the sender QObject method when you're inside a slot.

respondido 10 mar '12, 16:03

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.