我正在尝试将整数类型的
任何帮助解决问题的意见都非常感激。
以下是我的代码片段。 头文件
QList
从QML传递到C++代码中,但是我的方法似乎不起作用。使用以下方法时,我遇到了以下错误:left of '->setParentItem' must point to class/struct/union/generic type
type is 'int *'
任何帮助解决问题的意见都非常感激。
以下是我的代码片段。 头文件
Q_PROPERTY(QDeclarativeListProperty<int> enableKey READ enableKey)
QDeclarativeListProperty<int> enableKey(); //function declaration
QList<int> m_enableKeys;
cpp文件
QDeclarativeListProperty<int> KeyboardContainer::enableKey()
{
return QDeclarativeListProperty<int>(this, 0, &KeyboardContainer::append_list);
}
void KeyboardContainer::append_list(QDeclarativeListProperty<int> *list, int *key)
{
int *ptrKey = qobject_cast<int *>(list->object);
if (ptrKey) {
key->setParentItem(ptrKey);
ptrKey->m_enableKeys.append(key);
}
}
setParentItem
和m_enableKeys
不是int
的成员,但您尝试在key
和ptrKey
上调用它们,它们都是int*
,所以这永远不会起作用。 - stijnQDeclarativeListProperty
/QQmlListProperty
仅适用于提供只读的子项列表,这些子项是 QObject 派生的对象,并且该列表在实例化后无法修改。 - TheBootroo