c++ - 将字符串列表从 QML 发送到 C++

标签 c++ list qt qml

我有在 QML 中管理的 ListModel。编辑后我想将此模型发送到 C++(例如作为 QStringList,或者我可以在 C++ 中使用的其他东西)。

我知道我可以将列表从 C++ 公开到 qml 并从那里编辑它,但对于我的应用程序逻辑来说这并没有真正意义。我能以某种方式在 QML 中创建一个类似数据类型的列表,我可以用信号将其发送到 C++ 吗?

最佳答案

我认为您可以将 QStringList 发送到 C++ 代码,它会被处理。请参阅下面链接的文档。

string QML Basic Type

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/

相关文章:

c++ - QPointer::clear() 是否删除其引用的指针,或者 "Clears this QPointer object."是否有其他含义?

c++ - Visual Studio 报告结构 vector 上的 push_back() 函数调用错误

python - 根据行提取具有不同索引列的 pandas 数据框的值

c++ - Qt 便携工控机 : only QSharedMemory?

python - 两个列表(男孩和女孩)的所有可能(一夫一妻制)配对

c# - NHibernate/Transaction 如何只提交一个对象而不提交整个 session

qt - 如何向 qt Creator 添加预处理定义(宏)?

c++ - Pthread 参数传递

c++ - 使用结构标识符来表示 POD 类型和 C 结构

c++ - C++98 中获取并继续调用当前类不知道的类方法的最简单方法是什么?