当从c++发出的信号向QML发送数据时
When signal emitted from C++ send data to QML
如何做到这一点:当信号完成时,从c++发送变量replydata(从c++)到TextArea(qml)
我怎么连接这个?也许Q_PROPERTY是一个好方法?我使用Qt 5.3
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:///main.qml")));
SendGetSMS *Connection = new SendGetSMS();
engine.rootContext()->setContextProperty("abc1", Connection);
QObject::connect(Connection,&SendGetSMS::finishedReply,engine,...);
来自文档
c++中的:
class Message : public QObject
{
Q_OBJECT
Q_PROPERTY(QString author READ author WRITE setAuthor NOTIFY authorChanged)
public:
void setAuthor(const QString &a) {
if (a != m_author) {
m_author = a;
emit authorChanged();
}
}
QString author() const {
return m_author;
}
private:
QString m_author;
};
Message msg;
engine.rootContext()->setContextProperty("msg", &msg);
qml:
中的Text {
width: 100; height: 100
text: msg.author // invokes Message::author() to get this value
Component.onCompleted: {
msg.author = "Jonah" // invokes Message::setAuthor()
}
}
相关文章:
- 如何在不使用委托的 QML 中显示模型数据
- 如何在 QML 中使用从 c++ 公开的序列数据创建图表
- 将数据从 c++ 加载到 QML Scatter3d 项
- 有没有办法有效地更新QML中的CAN数据?
- 使用 QSortFilterProxyModel 对 Qml ListView 的数据进行排序
- 从QML ListView中QABStractListModel中的数据操纵数据
- QML自定义列表数据类型
- 将数据提供给 ChartView (LineSeries) - QML
- 如何将数据从 c++ "pull"到 qml?
- 从高度动态的C 数据模型中更新QML:计时器与属性绑定
- 如何向QML显示不断更新的c++数据
- 为什么我无法从 QML 读取公开的C++数据?
- 如何将数据从QML传递到C 作为可变参考
- 将二进制数据从QML传递到C
- 您将使用哪种数据模型在 QML 中制作二维字段 100*100
- 使 XML 数据显示在 Blackberry 10 Cascades QML 中的 listItemComponents
- 在具有多个视图的 QML 中查看、编辑和更新数据(来自C++),而数据保留在C++(订阅数据)中
- 用来自 std::map 的数据填充 QML 列表视图
- QT 哪些 QML/C++ 数据类型可以转换为 JSON
- QML 数据文件夹