SoloWang
SoloWang

Reputation: 1

How can i get parameters form signal which emitted by cpp in QML

I trigger a signal in .cpp file and parameters of this signal is integer arrays. Now i can successfully receive this signal in QML,but i don't know how to get the parameters. My code is just like this:

// .h
signals:
    void  mysignal(int a[]);
//.cpp
    int a[]={1,2,3,4,5};
    emit mysignal(a);
// QML
    Connections:{
        target:XXX
        onMysignal:
            // i don't know how to get the parameters here! Anyone can give me tips?
    }

Upvotes: 0

Views: 56

Answers (1)

eyllanesc
eyllanesc

Reputation: 243955

There is no equivalent for arrays in QML, what is very similar is to use a container like std::vector or QVector:

//.h
signals:
    void  mysignal(const std::vector<int> & a);
//.cpp
    std::vector<int> v = {1,2,3,4,5};
    emit mysignal(v);
//QML
Connections{
    target: XXX
    onMysignal: console.log(a)
}

Upvotes: 1

Related Questions