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

objects registered via qmlRegisterSingletonType are 0 when passed to a Q_INVOKABLE

    XMLWordPrintable

    Details

      Description

      When registering an object via qmlRegisterSingletonType, the object can't be passed back to C++ properly.

      The attached plugin + qml code shows the behavior, relevant snippets below.

      This might be related to QTBUG-30090.

      plugin.cpp
      ...
      
      void Test_SingletonPlugin::registerTypes(const char *uri)
      {
          // @uri Singleton
          qmlRegisterSingletonType<SingletonTest>(uri, 1, 0, "SingletonTest", singleton_provider);
      }
      
      singletontest.cpp
      ...
      
      void
      SingletonTest::testSingleton(QObject *obj)
      {
          qDebug() << "C++:" << obj;
      }
      
      SingletonTest.qml
      ...
      
              console.log(rect)
              SingletonTest.testSingleton(rect)
              console.log(SingletonTest)
              SingletonTest.testSingleton(SingletonTest)
      
      ...
      
      Example Output
      QQuickRectangle(0x22edaf0)
      C++: QQuickRectangle(0x22edaf0)
      SingletonTest(0x22dd330)
      C++: QObject(0x0)
      

        Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            • Assignee:
              aalpert Alan Alpert
              Reporter:
              saviq Michał Sawicz
            • Votes:
              2 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Gerrit Reviews

                There are no open Gerrit changes