Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Cannot register structs/classes with Q_DECLARE_METATYPE
Forum Updated to NodeBB v4.3 + New Features

Cannot register structs/classes with Q_DECLARE_METATYPE

Scheduled Pinned Locked Moved Unsolved General and Desktop
13 Posts 5 Posters 1.2k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M markovvv

    @SGaist Thanks for reply!

    Unfortunately registering std::pair template is not working, teplate is already registered:
    /home/work/*****/src/common/common_data/GlobalChannelIdentifier.h:35:1: error: redefinition of ‘struct QMetaTypeId<std::pair<_T1, _T2> >’
    35 | Q_DECLARE_ASSOCIATIVE_CONTAINER_METATYPE(std::pair)

    And declaring meta type for std::uintptr_t doesnt work out too.
    Could u try the code on your system please? This problem occured while transitioning code from qt5 to qt6.
    Thanks!

    Axel SpoerlA Offline
    Axel SpoerlA Offline
    Axel Spoerl
    Moderators
    wrote on last edited by Axel Spoerl
    #4

    @markovvv
    Something else is wrong here, I suspect.
    The code compiles for me (Linux x86_64, Qt 6.7, 6.8)

    Software Engineer
    The Qt Company, Oslo

    1 Reply Last reply
    2
    • M markovvv

      @SGaist Thanks for reply!

      Unfortunately registering std::pair template is not working, teplate is already registered:
      /home/work/*****/src/common/common_data/GlobalChannelIdentifier.h:35:1: error: redefinition of ‘struct QMetaTypeId<std::pair<_T1, _T2> >’
      35 | Q_DECLARE_ASSOCIATIVE_CONTAINER_METATYPE(std::pair)

      And declaring meta type for std::uintptr_t doesnt work out too.
      Could u try the code on your system please? This problem occured while transitioning code from qt5 to qt6.
      Thanks!

      SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #5

      @markovvv
      In addition to @Axel-Spoerl, which distribution are you using ?
      Which version of gcc ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      M 1 Reply Last reply
      0
      • SGaistS SGaist

        @markovvv
        In addition to @Axel-Spoerl, which distribution are you using ?
        Which version of gcc ?

        M Offline
        M Offline
        markovvv
        wrote on last edited by markovvv
        #6

        @SGaist Iam using opensuse Leap 15.5 and version of gcc is 12

        C Axel SpoerlA 2 Replies Last reply
        0
        • M markovvv

          @SGaist Iam using opensuse Leap 15.5 and version of gcc is 12

          C Offline
          C Offline
          ChrisW67
          wrote on last edited by
          #7

          This code compiles as-is for me (Qt 6.6)

          #include <QCoreApplication>
          #include <utility>
          
          struct GlobalChannelParams { }; // faked
          
          struct GlobalChannelIdentifier : std::pair<std::uintptr_t, int> {
              using pair::pair;
          
              struct Hash {
                  std::size_t operator()(const GlobalChannelIdentifier &gi) const noexcept;
              };
          
              friend std::ostream &operator<<(std::ostream &s, const GlobalChannelIdentifier &id);
          };
          
          GlobalChannelIdentifier GetGlobalChannelIdentifier(const GlobalChannelParams &gci) noexcept;
          
          Q_DECLARE_METATYPE(GlobalChannelIdentifier)
          
          int main(int argc, char **argv) {
                  QCoreApplication app(argc, argv);
                  return 0;
          }
          

          Using either of these:

          g++-11 (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0  // platform default
          g++-12 (Ubuntu 12.3.0-1ubuntu1~22.04) 12.3.0
          

          So this does not seem to be an obvious compiler version issue.

          1 Reply Last reply
          0
          • M markovvv

            @SGaist Iam using opensuse Leap 15.5 and version of gcc is 12

            Axel SpoerlA Offline
            Axel SpoerlA Offline
            Axel Spoerl
            Moderators
            wrote on last edited by
            #8

            @markovvv
            I am on openSuSE Tumbleweed, it compiles with gcc12 and 13.
            Reading the compile error again, you may wanna check whether #include <utility>is missing or skipped by a pragma. Looks the compiler doesn't know std::pair, when Q_DECLARE_METATYPE is expanded.

            Software Engineer
            The Qt Company, Oslo

            M 1 Reply Last reply
            0
            • Axel SpoerlA Axel Spoerl

              @markovvv
              I am on openSuSE Tumbleweed, it compiles with gcc12 and 13.
              Reading the compile error again, you may wanna check whether #include <utility>is missing or skipped by a pragma. Looks the compiler doesn't know std::pair, when Q_DECLARE_METATYPE is expanded.

              M Offline
              M Offline
              markovvv
              wrote on last edited by
              #9

              Thanks u guys for all of the input! @Axel-Spoerl utility is included. Since iam transfering application from qt5 to qt6, is there any possibility, that there is a qt version collision? Iam out of the ideas, what could be possibly wrong. Application on qt5 compiled fine.

              Axel SpoerlA C 2 Replies Last reply
              0
              • M markovvv

                Thanks u guys for all of the input! @Axel-Spoerl utility is included. Since iam transfering application from qt5 to qt6, is there any possibility, that there is a qt version collision? Iam out of the ideas, what could be possibly wrong. Application on qt5 compiled fine.

                Axel SpoerlA Offline
                Axel SpoerlA Offline
                Axel Spoerl
                Moderators
                wrote on last edited by
                #10

                @markovvv

                Really hard to guess.
                If out of ideas, I'd start isolating the conflicting behavior into a small reproducer and see whether it happens there. Even if utilities are included and recognized by the code model of your IDE, the compiler might still not see it due to #ifdef'ry or pragma one cascades.

                Software Engineer
                The Qt Company, Oslo

                1 Reply Last reply
                0
                • M markovvv

                  Thanks u guys for all of the input! @Axel-Spoerl utility is included. Since iam transfering application from qt5 to qt6, is there any possibility, that there is a qt version collision? Iam out of the ideas, what could be possibly wrong. Application on qt5 compiled fine.

                  C Offline
                  C Offline
                  ChrisW67
                  wrote on last edited by
                  #11

                  @markovvv Does the self-contained code I posted compile?

                  M 1 Reply Last reply
                  0
                  • C ChrisW67

                    @markovvv Does the self-contained code I posted compile?

                    M Offline
                    M Offline
                    markovvv
                    wrote on last edited by
                    #12

                    @ChrisW67 Yeah, it does

                    Christian EhrlicherC 1 Reply Last reply
                    0
                    • M markovvv

                      @ChrisW67 Yeah, it does

                      Christian EhrlicherC Online
                      Christian EhrlicherC Online
                      Christian Ehrlicher
                      Lifetime Qt Champion
                      wrote on last edited by
                      #13

                      @markovvv said in Cannot register structs/classes with Q_DECLARE_METATYPE:

                      Yeah, it does

                      So it has neither something to do with the Qt version nor with the compiler but with your code (organisation) - reduce your code until the error is gone and you found the problem.

                      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                      Visit the Qt Academy at https://academy.qt.io/catalog

                      1 Reply Last reply
                      1

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved