Signal and slots qRegisterMetaType



  • Hi guys,

    I'm having a strange problem with some custom typedefs i have defined for smart pointers e.g:
    @
    namspace example
    {
    typedef
    smartPointer;
    }@

    Then a qthead that emits a signal of this type back to a class that runs on the main gui thread:

    @namspace example
    {
    class thread : public QThread
    {
    Q_Object

       public signals:
      void  send(smartPointer);
    

    }
    }@

    Hopefully this short example makes sense.

    I have registered this typedef with the @qRegisterMetaTypeexample::smartPointer(smartPointer);@

    class, and also the QDECLARE_METATYPE(example::smartPointer) macro.

    However in runtime I get a "cannot queue arguments of type example (Make sure 'example' is a registered using qRegisterMetaType().)" error.

    any sugestions would be great



  • [quote author="Suths" date="1352298159"]
    I have registered this typedef with the @qRegisterMetaTypeexample::smartPointer(smartPointer);@
    class[/quote]

    Where exactly do you call that function?


  • Moderators

    You seem to be missing something in your typedef. I'll assume this is something like
    @typedef SomeGiantTypeThatIDontWantToRetypeOrWhatever SmartPointer;@

    qRegisterMetaType takes a string name of your class e.g. @qRegisterMetaTypeexample::SmartPointer("SmartPointer")@

    You can call it wherever just as long as your typedef is visible there and before you use it for connecting or access its metadata.
    Also, make sure you use Q_DECLARE_METATYPE outside of your example namespace.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.