我有在 QML 中管理的 ListModel。编辑后我想将此模型发送到 C++(例如作为 QStringList,或者我可以在 C++ 中使用的其他东西)。
我知道我可以将列表从 C++ 公开到 qml 并从那里编辑它,但对于我的应用程序逻辑来说这并没有真正意义。我能以某种方式在 QML 中创建一个类似数据类型的列表,我可以用信号将其发送到 C++ 吗?
最佳答案
我认为您可以将 QStringList
发送到 C++ 代码,它会被处理。请参阅下面链接的文档。
When integrating with C++, note that any QString value passed into QML from C++ is automatically converted into a string value, and vice-versa.
Data Type Conversion Between QML and C++
Sequence Type to JavaScript Array
Certain C++ sequence types are supported transparently in QML as JavaScript Array types.
In particular, QML currently supports:
QList<int> QList<qreal> QList<bool> QList<QString> and QStringList QList<QUrl>
关于c++ - 将字符串列表从 QML 发送到 C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34222046/