我试图通过从QML到C++代码的整数QList
,但不知何故我的方法不起作用。下面的方法我收到以下错误:如何将QList从QML传递到C++/Qt?
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 *,因此它们将永远不会工作。 – stijn
请记住'QDeclarativeListProperty' /'QQmlListProperty'仅用于提供QObject派生子对象的只读列表,并且该实例在实例化之后不能被修改。 – TheBootroo