Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Qobject_cast, trying to determine object class...
Zerby last edited by
I have a MainWindow class, where in the eventFilter I have this:
QChildEvent ce =(QChildEvent)event;
QObject *obj = ce->child();
Then I have the childAdded signal connected to MainWindow::handleAddedObject(QObject *obj). Inside that I do:
baseWidget *w = qobject_cast<baseWidget *>(obj);
if (w != 0) this->baseWidgetAdded(w);
Then I try it with:
MainWindow *w = new MainWindow();
baseWidget *w1 = new baseWidget(w);
The handleAddedObject -function get called, but the qobject_cast returns 0 everytime. It must be the baseWidget w1 that triggers the function calls, because if I comment out the line where I create the baseWidget object, the handleAddedObject is not called at all. What am I doing wrong?