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. qRegisterMetaType of custom C-style struct for usae with QSignalSpy in QTest
QtWS25 Last Chance

qRegisterMetaType of custom C-style struct for usae with QSignalSpy in QTest

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 2 Posters 3.7k 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.
  • V Offline
    V Offline
    Vasiliy
    wrote on 29 Feb 2016, 15:28 last edited by
    #1

    Hi,
    1. I have C headers for driver, which contains a lot of structures. I use the structures as signals' arguments. Here is example of a such a like structure (most simple one just for example)

    typedef struct
    {
    	uint16_t Capabilities;
    } PingSrspFormat_t;
    

    2. I've made simplest QTest, and in 'testCase1()' try to get signals from my DUT object this way:

    	// 1. Register custom C-Style struct type
    qRegisterMetaType<PingSrspFormat_t>("PingSrspFormat_t"); 
    	// 2. Connect signal of my DUT object (znpHost) already instantiated above
    QSignalSpy spy(znpHost,SIGNAL(pfnSysPingSrsp(const PingSrspFormat_t&)));
    	// 3. just in case clear spy list
    spy.clear();
    	// 4. issue method of my DUT object to get signal from it
    znpHost->sysPing(); 
    	// 5. wait for a while..
    spy.wait(500);
    	// 6. get the signal argument
    PingSrspFormat_t result = qvariant_cast<PingSrspFormat_t>(spy.at(0).at(0));
    	// 7. check the argument
    QVERIFY(result.Capabilities == 0x0000); 
    

    3. due compilation get an error:

    /home/dev/Qt/5.5/gcc_64/include/QtCore/qglobal.h:703: error: invalid application of 'sizeof' to incomplete type 'QStaticAssertFailure<false>'
         enum {Q_STATIC_ASSERT_PRIVATE_JOIN(q_static_assert_result, __COUNTER__) = sizeof(QStaticAssertFailure<!!(Condition)>)}
                                                                                         ^
    

    Any suggestions how to fix the compilation error are very welcome

    Thanks

    1 Reply Last reply
    0
    • K Offline
      K Offline
      kshegunov
      Moderators
      wrote on 29 Feb 2016, 17:18 last edited by
      #2

      @Vasiliy
      Hello,
      Do you have Q_DECLARE_METATYPE(PingSrspFormat_t) at the appropriate place?

      Kind regards.

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      1
      • V Offline
        V Offline
        Vasiliy
        wrote on 29 Feb 2016, 17:20 last edited by
        #3

        Hi!

        • Well, should i put the macros in C headers?
        • Am I correct if say that for signal/slot usage of qRegisterMetaType is enough?

        Thanks for reply

        K 1 Reply Last reply 29 Feb 2016, 17:25
        0
        • V Vasiliy
          29 Feb 2016, 17:20

          Hi!

          • Well, should i put the macros in C headers?
          • Am I correct if say that for signal/slot usage of qRegisterMetaType is enough?

          Thanks for reply

          K Offline
          K Offline
          kshegunov
          Moderators
          wrote on 29 Feb 2016, 17:25 last edited by
          #4

          @Vasiliy
          Hello,
          Usually you put the macro after the declarations, however I believe the moc will be forgiving enough if you put it into your own header (not to modify the externals). Something like this in mycwrapheader.h:

          #include <somecheader.h>
          
          Q_DECALARE_METATYPE(PingSrspFormat_t)
          // ... more code
          

          Am I correct if say that for signal/slot usage of qRegisterMetaType is enough?

          Whether or not this is true is besides the point, because you're making a qvariant_cast and for that you'd need the Q_DECLARE_METATYPE macro. Additionally, you need to register the type with the runtime (through qRegisterMetaType) only if you're using queued connections (usually when multithreading is involved).

          Kind regards.

          Read and abide by the Qt Code of Conduct

          1 Reply Last reply
          1
          • V Offline
            V Offline
            Vasiliy
            wrote on 29 Feb 2016, 17:26 last edited by
            #5

            @kshegunov wow!
            Seems you are right I've just put the macros at hte top of my Unity test *.cpp right after all #includes and the compilation passed!
            Thanks a lot for the advice!

            K 1 Reply Last reply 29 Feb 2016, 17:31
            0
            • V Vasiliy
              29 Feb 2016, 17:26

              @kshegunov wow!
              Seems you are right I've just put the macros at hte top of my Unity test *.cpp right after all #includes and the compilation passed!
              Thanks a lot for the advice!

              K Offline
              K Offline
              kshegunov
              Moderators
              wrote on 29 Feb 2016, 17:31 last edited by kshegunov
              #6

              @Vasiliy
              No problem, however you should really put that macro in a header .h, not in your source file .cpp. :)

              Read and abide by the Qt Code of Conduct

              V 1 Reply Last reply 29 Feb 2016, 17:34
              1
              • K kshegunov
                29 Feb 2016, 17:31

                @Vasiliy
                No problem, however you should really put that macro in a header .h, not in your source file .cpp. :)

                V Offline
                V Offline
                Vasiliy
                wrote on 29 Feb 2016, 17:34 last edited by
                #7

                @kshegunov yes, you are correct, but for fast issue fix it was ok to put it in *.cpp :) now I can gloss the code with calm after your great advice!
                Thanks!

                1 Reply Last reply
                0

                3/7

                29 Feb 2016, 17:20

                • Login

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