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

Cannot call slot or Q_INVOKABLE from QML in QQmlPropertyMap subclass

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • 5.1.0
    • 5.0.0
    • None
    • Windows 7, both x64 and x86.
      QtCreator 2.6.0 and 2.6.1.
      Compiler is Microsoft Visual C++ Compiler 10.0 (x86).

    Description

      Created a subclass of QQmlPropertyMap, which is then passed to QML as a context property. Also implemented a slot in that subclass.

      Expected that when the QML form is clicked, containing a request to call the slot, the code in the slot would run. Instead, I get this console error output:

      TypeError: Property 'testFunc' of object TestMap(0x20320f8) is not a function

      If I change my class to derive instead directly from QObject, then I get the expected output and the slot fires as normal.

      With the attached sample app, running the app and clicking anywhere in the QML window should produce a qDebug output saying "Success", but it gives the above-mentioned error. What's more, changing the TestMap class to derive from QObject instead of QQmlPropertyMap (and changing the constructor accordingly) allows the slot to fire as expected. Therefore, there is something in the implementation of QQmlPropertyMap that prohibits QML from seeing the slots or Q_INVOKABLEs put in its child classes.

      I have Q_OBJECT macro included. I can connect Qt signals to this slot, and they fire normally. And, since the text in the QML (as bound to this object) shows up correctly, the object is being passed to the context correctly. The only issue is that QML itself cannot fire the slot/Q_INVOKABLE.

      If this is expected behavior, it should be noted as such and explained in the documentation.

      Attachments

        Issue Links

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

          Activity

            People

              mardy Alberto Mardegan
              kanders Keith Anders
              Votes:
              3 Vote for this issue
              Watchers:
              14 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes