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

Cannot register both const and non-const versions of a type with QML

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.5.0
    • None
    • Windows 10

    Description

      The situation I've found involves:
      2 interfaces:
      1st interface) allows the user to modify an exposed setting property (non-const) to initialize it in preparation for a session.
      2nd interface) receives a copy of the settings type, which is used to initialize its own (const) setting property. Existing classes may desire to poll the setting property of this class to determine the active session's settings, but they should not be able to modify those settings.

      class Settings : public QObject
      {
          Q_OBJECT
          // properties
      };
      QML_DECLARE_TYPE(Settings)
      QML_DECLARE_TYPE(const Settings)
      
      class Interface1 : public QObject
      {
          Q_OBJECT
      ...
          Q_PROPERTY(Settings* settings READ settings CONSTANT FINAL)
      ...
          Settings* settings() const;
      ...
      };
      
      class Interface2 : public QObject
      {
          Q_OBJECT
      ...
          Q_PROPERTY(const Settings* settings READ settings CONSTANT FINAL)
      ...
          const Settings* settings() const;
      ...
      };
      
      main () {
      ...
          qmlRegisterType<const Settings>("My.Uri", 1, 0, "MyConstSettings");
          // Adding the following line produces a runtime error that "breaks binary compatibility" (even after manually wiping the shadow build directory and starting a fresh rebuild/run)
          qmlRegisterType<Settings>("My.Uri", 1, 0, "MySettings");
      ...
      }

      Receive the following error:
      "QMetaType::registerType: Binary compatibility break.
      Type flags for type 'Settings*' [1058] don't match. Previously registered TypeFlags(0x104), now registering TypeFlags(0x10c). This is an ODR break, which means that your application depends on a C++ undefined behavior.
      Hint: "

      Due to the error described above, it appears that both const Type * and (non-const) Type * cannot be registered simultaneously.

      Attachments

        Issue Links

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

          Activity

            People

              Unassigned Unassigned
              dchamberlain David Chamberlain
              Votes:
              4 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes