0

Is it possible to set a QObject as parent of a QWidget, so the QWidget is deleted when the QObject is deleted?

The following code doesn't compile:

QObject a;
QObject b;
QWidget c;

b.setParent(&a); // This works
c.setParent(&a); // This fails: error C2664: 'void QWidget::setParent(QWidget *,Qt::WindowFlags)': cannot convert argument 1 from 'QObject *' to 'QWidget *'

Even though QWidget inherits from QObject! So why is the setParent(QObject*) function not available in QWidget anymore?

Jan Rüegg
  • 9,587
  • 8
  • 63
  • 105

0 Answers0