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

qRegisterMetatype invalidates type check in setProperty

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Not Evaluated Not Evaluated
    • None
    • 5.1.1
    • Core: Object Model
    • None
    • Linux, Windows

      QObject::setProperty normally checks that the passed-in type can be converted to the target type and doesn't call the setter function if it cannot. This works with user-defined variant types as well: if you pass a wrong type, the setter function won't be called at all.

      However, when the custom type is registered with qRegisterMetatype, the check no longer works. If you pass an object of a wrong type to setProperty, the setter function will be called with an object that is filled with zeros. This is fatal for example with classes that contain a d pointer.

      The attached project illustrates this. Commenting out qRegisterMetaType() solves the problem.

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

            thiago Thiago Macieira
            topiolli Topi Mäenpää
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes