QML Connections: Implicitly defined onFoo properties in Connections are deprecated

China☆狼群 提交于 2020-12-05 00:51:45

问题


I got the following error message when upgraded to Qt 5.15:

QML Connections: Implicitly defined onFoo properties in Connections are deprecated.
Use this syntax instead: function onFoo(<arguments>) { ... }

The corresponding QML code is pasted below

Connections {
    target: AppProxy

    onLogsReady: function(logs) {
        textLogs.text = logs
    }
}

where the onLogsReady is a signal defined in the AppProxy class:

class AppProxy : public QObject {
  Q_OBJECT
  Q_DISABLE_COPY(AppProxy)

 public:
  AppProxy(QObject* parent = 0);
  ~AppProxy();

 signals:
  void logsReady(QString logs);

// ...
};

I wonder how to suppress this warning.


回答1:


in Qml 5.15 there is a new syntax for connections. In your case it would look like this:

Connections {
    target: AppProxy

    function onLogsReady(logs) {
        textLogs.text = logs
    }
}

You can read more about it here: https://doc.qt.io/qt-5/qml-qtqml-connections.html



来源:https://stackoverflow.com/questions/62297192/qml-connections-implicitly-defined-onfoo-properties-in-connections-are-deprecat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!