Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Can't call QObject::setParent()
kitfox last edited by kitfox
I have some code that used to compile and run. However, my latest attempt is refusing to compile. Even though my classes publicly extend QObject, I'm getting errors saying
'class Gf::Attribute' has no member named 'setParent'.
Infact, even the following code causes 'no member named 'setParent' in 'QObject'':
QObject* a = new QObject(); QObject* b = new QObject(); a->setParent(b);
Even qobject.h doesn't list setParent() as a member. It still appears as a public member function in the docs, though. I'm using Qt 5.12.3. What's going on? Was QObject::setParent() taken out of the API? If so, how do I set the parent?
Even qobject.h doesn't list setParent() as a member.
It sounds like your local copy of qobject.h was (accidentally?) modified.
QObject::setParent()definitely exists in Qt 5.12.3: https://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/kernel/qobject.h?h=5.12.3#n204
A quick fix is to replace your qobject.h with the version in the link above, but this won't repair other files that might have been modified. To be sure that everything is fixed, uninstall and reinstall your copy of Qt 5.12.3.
kitfox last edited by
Reinstalling Qt worked. Thanks.
I still have no idea what I could have done to corrupt things.
@kitfox If you do global rename/refactor, it is possible to modify the Qt or compiler headers too.
I'd recommend to make them readonly to prevent such accidental changes.