当从c++发出的信号向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()
    }
}

相关内容

  • 没有找到相关文章

最新更新