如何做到这一点:当信号完成时,从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()
}
}