Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-104361

[REG: 6.1->6.2] QMetaObject::invokeMethod of qml function has no effect

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P1: Critical
    • Resolution: Fixed
    • Affects Version/s: 6.2.4, 6.3.1
    • Fix Version/s: 6.2.5, 6.4.0 FF
    • Component/s: QML: Compiler
    • Environment:
      Win 10 Pro 64bit 10.0.19044, Build 19044. Qt 6.3.1. Compiler MSVC2019 16.6.30225.117 amd64
    • Platform/s:
      Windows
    • Commits:
      c8e756e560ce3f0d369df65986e5578e0e963c66 fa8dc8c40b (qt/tqtc-qtdeclarative/6.2) 7eb012ebd9 (qt/qtdeclarative/6.3)

      Description

      Both in release and debug mode, if the Quick Compiler is enabled, the invocation of the function has no effect. If the Quick compiler is disabled, it works. If we add a console.log('') call inside the function, the function has effect again. Probably, after the translation from js to cpp, the cpp code gets compiled in a way that the call is optimized away. Inserting the line console.log('') prevents the translation to cpp primitives and so the function is correctly invoked

       

      // main.cpp
      #include <QGuiApplication>
      #include <QQmlApplicationEngine>
      #include <QTimer>
      #include <QQmlComponent>
      #include <QWindow>int main(int argc, char *argv[])
      {
          QGuiApplication app(argc, argv);    QQmlApplicationEngine engine;
          const QUrl url(QStringLiteral("qrc:/main.qml"));
          QQmlComponent component(&engine, url);
          QWindow *window = qobject_cast<QWindow*>(component.create());
          QTimer::singleShot(2000, window, [window](){
              QMetaObject::invokeMethod(window, "movePoint", Q_ARG(QPointF, QPointF(200, 200)));
          });    return app.exec();
      }
      
      //main.qml
      import QtQuick
      import QtQuick.Window
      
      Window {
          width: 640
          height: 480
          visible: true
          title: qsTr("Hello World")
      
          function movePoint(position: point) {
              test.x = position.x
              test.y = position.y
          }
      
          Rectangle {
              id: test
              width: 200
              height: 200
              color: "green"
          }
      }
      
      
      

        Attachments

        1. QmlFunctionTest.zip
          2 kB
          Lorenzo Lucignano
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            Assignee:
            ulherman Ulf Hermann
            Reporter:
            lorenzolightsgdwarf Lorenzo Lucignano
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes