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

qRegisterMetaType fails to compile with SEQUENTIAL_CONTAINER_METATYPE std::array<uint8_t, 10>

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 6.5.3, 6.6.1
    • None
    • All

    Description

      In Qt5, I was able to create a Q_GADGET wrapper around data types for a non-Qt data stream. This allowed me to move data around using Qt Remote Objects and visualize it in QML.

      Raw data stream --> Qt preprocessing app --> QtRO --> HMI App

      Looking at porting to Qt6, I'm hitting issues due to changes in qmetatypes.h and the new qiterable.h, specifically for arrays of elements.

      I can't change the underlying data stream, so in Qt5, I cast (for instance) a uint8_t array (`uint8_t values[10]`) to `std::array<uint8_t, 10>`, then use `Q_DECLARE_SEQUENTIAL_CONTAINER_METATYPE` and `qRegisterMetaType`. This works in Qt5 (with one needed hack*).

      In Qt6, this fails asserts in qiterable.h (same assert on line 49 as well).

      The root cause appears to be using `QConstPreservingPointer<void, quint16>` from line 417, which uses quint16 for Storage. I guess std::vector and std::list (the types Qt applies Q_DECLARE_SEQUENTIAL_CONTAINER_METATYPE to by default) have alignof() size of pointer, but std::array provides alignof() size of the underlying type (1 for uint8_t), which fails the assert.

      It is unclear to me why quint16 is needed for Storage here (and not needed in Qt5), so am I not sure how to work around this issue.

      *The hack is that Q_DECLARE_SEQUENTIAL_CONTAINER_METATYPE expects a SINGLE_ARG_TEMPLATE, so I need to define

      template<class T>
      using array10 = std::array<T, 10>;
      Q_DECLARE_SEQUENTIAL_CONTAINER_METATYPE(array10)
      

      This doesn't affect the bug, but explains why it is present in the minimal example attached.

      Attachments

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

        Activity

          People

            ulherman Ulf Hermann
            bstottle Brett Stottlemyer
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes