这是否可能具有 QObjects 和(例如) QGraphicsWidgets 的树状结构?我的意思是,我不能写像这样的初始化列表:
class MyButton : public QGraphicsWidget
{
Q_OBJECT
public:
MyButton(int buttonId, QObject *parent = 0) : QObject(parent)
{
}
然后,就像
myButton = new MyButton(id, myObject);
我应该做 .setParent 还是什么?
更新:查看实际分配:
class myObject : public QObject
{
Q_OBJECT
public:
MyObject(QObject *parent = 0) : QObject(parent) {
}
MyButton *myButton;
void showButton(){
myButton = new MyButton(id, this); //no matching function for call to 'MyButton::MyButton(MyObject* const)'
//note: no known conversion for argument from 'MyObject* const' to 'QGraphicsObject*'
}
};