简体   繁体   中英

connect c++ object signal to QML signal handler with enum parameter

I have the following c++ plugin code:

class NetworkManager : public QObject
{
Q_OBJECT

...
enum WIFIStat{
    STAT_NOTINITED,
    STAT_INITED
};
Q_ENUM(WIFIStat)

 Q_PROPERTY(WIFIStat wifiStatus READ wifiStatus NOTIFY wifiStatusChanged)

and i want to connect to a signal handler in QML:

signal wifiStatusChanged(WIFIStat wifiStatus);

onWifiStatusChanged: {
    console.log(wifiStatus)
}

Component.onCompleted: {
   network_manager.wifiStatusChanged.connect(wifiStatusChanged);
}

but i'm getting the follwing error:

Invalid signal parameter type: WIFIStat

How can i define the enum NetworkManager::WIFIStat type parameter int the handler function?

I solved the problem using var in my handler function parameter:

signal wifiStatusChanged(var wifiStatus);

but i ended up using another approach as stated here: https://stackoverflow.com/a/29202462/2614418

Connections{
    target: network_manager
    onWifiStatusChanged: {
        console.log("Status:"+wifiStatus)
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM