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. Int qRegisterMetaType (const char *typeName) & int qRegisterMetaType() difference
Forum Update on Monday, May 27th 2025

Int qRegisterMetaType (const char *typeName) & int qRegisterMetaType() difference

Scheduled Pinned Locked Moved General and Desktop
8 Posts 4 Posters 4.3k Views
  • 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.
  • I Offline
    I Offline
    ixSci
    wrote on last edited by
    #1

    Hi! Could you please explain me what is the difference between them?

    1 Reply Last reply
    0
    • F Offline
      F Offline
      Franzk
      wrote on last edited by
      #2

      qRegisterMetaType(const char *) enables you to add a name to the meta type, so you can get the type by name as well. Probably useful on some platforms.

      "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • I Offline
        I Offline
        ixSci
        wrote on last edited by
        #3

        It is definitely not the solely difference between them. Because with second version I have complaining in runtime in queued signals/slots. When I emit signal in one thread and capture it in other one with QSignalSpy I have a complaint when try to cast an argument to my type. I have no complaints with 1st version.

        1 Reply Last reply
        0
        • N Offline
          N Offline
          Nierob
          wrote on last edited by
          #4

          I strongly advise to always use version taking name, in some places in Qt the name is checked to provide additional functionality. It is extremely important when you use QtDeclarative, QtScirpt or QtDbus.

          Try to use Q_DECLARE_METATYPE() macro instead, it is superior in many aspects (for example it will work with QVariant too).


          Nierob

          1 Reply Last reply
          0
          • I Offline
            I Offline
            ixSci
            wrote on last edited by
            #5

            Well, I've actually found the answer on this question and even wrote article about it. It is in Russian though.

            >> Try to use Q_DECLARE_METATYPE() macro instead

            You can't use it instead you should use it in conjunction. qRegisterMetaType complements Q_DECLARE_METATYPE.

            Version with name and without name are really the same(one is called from another actually). With only one difference in behavior: when you register type which is located in namespace it will register type with namespace prefix. And qRegisterMetaType with name argument allows you to register name without namespace prefix. That is it.

            1 Reply Last reply
            0
            • N Offline
              N Offline
              Nierob
              wrote on last edited by
              #6

              You are fast, I was about to correct my comment :-)


              Nierob

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on last edited by
                #7

                [quote author="ixSci" date="1334222143"]
                Version with name and without name are really the same(one is called from another actually). With only one difference in behavior: when you register type which is located in namespace it will register type with namespace prefix. And qRegisterMetaType with name argument allows you to register name without namespace prefix. That is it.[/quote]

                Could you perhaps clarify the above (bold) a little bit more? Which version are you talking about there exactly?

                1 Reply Last reply
                0
                • I Offline
                  I Offline
                  ixSci
                  wrote on last edited by
                  #8

                  qRegisterMetaType() registers type with namespace prefix, if any. You can't change it.
                  qRegisterMetaType (const char *typeName) allows to set particular name, so you can register type w/o namespace prefix

                  1 Reply Last reply
                  0

                  • Login

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