QML Connections: Implicitly defined onFoo properties in Connections are deprecated

Viewed 13400

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.

3 Answers

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

In addtion to @luffy and @Lidekys solution in my case adding this line to pro file of the project is solved issue.

DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

@luffy answer is correct, but not completely. If you'll just make these changes, at least for me, it didn't fix the issue. What fixed it was adding "import QtQml 2.15" (like stated in https://doc.qt.io/qt-5/qml-qtqml-connections.html) in the qml files that were affected by these changes.

Not sure if this helps, just wanted to add in to the issue.

Related