从 QML 到 C++ 代码的 ComboBox 的 CurrentIndex

问题描述 投票:0回答:0

我想在QML中获得

currentIndex
ComboBox

我怎样才能得到它?

在 C++ 中,我尝试在

Q_INVOKABLE
时从 QML 代码调用
onCurrentIndexChanged
函数,但似乎我只能将
QObject*
作为参数传递给 QML 中的这些函数。所以,看来我不能只传递一个
int
,否则我会得到错误

"Could not convert argument 0 at"
...
"Passing incompatible arguments to C++ functions from JavaScript is dangerous and deprecated."
"This will throw a JavaScript TypeError in future releases of Qt!"

我试图在互联网上查找,但我没有找到任何直接的东西。我不敢相信没有简单的方法可以从 C++ 代码中获取

currentIndex
。也许我以错误的方式使用 QML。

一些示例的链接也将不胜感激。 ComboBox 模型是用 C++ 定义的,它是一个

QList<MyObject>
MyObject
NOT a
QObject
.

c++ qt combobox qml
© www.soinside.com 2019 - 2024. All rights reserved.