21

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.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Haozhe Xie
  • 3,438
  • 7
  • 27
  • 53

3 Answers3

35

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

luffy
  • 2,246
  • 3
  • 22
  • 28
  • 2
    I didn't find the minimum Qt version for this new syntax which would be handy to know for backwards compatibility. **edit** found https://github.com/qt/qtdeclarative/commit/a2eef6b511988b2435c4e39b6b5551e857ce7775 which says `Unfortunately that syntax is not available in Qt5.12.` – z3ntu Jun 13 '20 at 21:01
  • To add further, here's the commit that added the warning: https://github.com/qt/qtdeclarative/commit/efe0bec9468d75b768d1e26d2a8b440ade5ba632 – Zren Jun 20 '20 at 03:53
  • 1
    It looks like there will be a new logging category in Qt 5.15.1 (released August 2020). You'll be able to use `QT_LOGGING_RULES="qt.qml.connections=false"` I think. – Zren Jun 20 '20 at 03:55
  • 2
    So... 5.15. throws this warning and version 5.12 does not support this new syntax. Is there a `good practice™` to support both? Appplies to PySide2 usages for example which may vary in their Qt version. Thanks. – sausix Dec 31 '20 at 13:12
0

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
user2807083
  • 2,962
  • 4
  • 29
  • 37
-1

@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.

Lidekys
  • 19
  • 5