Results 1 to 5 of 5

Thread: QMetaType usage

  1. #1
    Join Date
    Oct 2006
    Posts
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QMetaType usage

    Hi,

    I have a non-Qt type that I am trying to use in a signal/slot connection. I would like to do the following:

    In Header

    Qt Code:
    1. class MyClass
    2. {
    3. ...
    4. signals:
    5. void negotiate( const unsigned int& timeout, const eos::ResourceSetRequest& request );
    6. ...
    7. }
    To copy to clipboard, switch view to plain text mode 

    In CPP

    Qt Code:
    1. void MyClass::someFunction()
    2. {
    3. emit negotiate( timeout, request );
    4. }
    To copy to clipboard, switch view to plain text mode 

    However, when I try this the connection isn't being made. From the documentation it looks like I need to register the type eos::ResourceSetRequest as a QMetaType before it can be sent as a signal argument.

    Is this correct?

    If so, then how do I register the non-Qt type as a new QMetaType?

    It looks like I need to place the following in the CPP file:
    Qt Code:
    1. Q_DECLARE_METATYPE(eos::ResourceSetRequest);
    2. int reqID = qRegisterMetaType<eos::ResourceSetRequest>("eos::ResourceSetRequest");
    To copy to clipboard, switch view to plain text mode 

    However, when I do this I get the following compile error:
    c:\Qt\4.1.4\include\QtCore\../../src\corelib\kernel\qmetatype.h(85) : error C2512: 'eos::ResourceSetRequest' : no appropriate default constructor available
    c:\Qt\4.1.4\include\QtCore\../../src\corelib\kernel\qmetatype.h(97) : see reference to function template instantiation 'void *qMetaTypeConstructHelper<T>(const T *)' being compiled
    with
    [
    T=eos::ResourceSetRequest
    ]
    DeviceQResourceFrame.cpp(22) : see reference to function template instantiation 'int qRegisterMetaType<eos::ResourceSetRequest>(const char *,T *)' being compiled
    with
    [
    T=eos::ResourceSetRequest
    ]

    Is this a Qt problem or a problem with constructing the non-Qt class?

    Any advice on this would be greatly appreciated.
    Last edited by wysota; 20th December 2006 at 10:12. Reason: missing [code] tags

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QMetaType usage

    As it says in the docs:
    Any class or struct that has a public constructor, a public copy constructor, and a public destructor can be registered.
    Make sure that eos::ResourceSetRequest compliances with the requirements.
    J-P Nurmi

  3. #3
    Join Date
    Oct 2006
    Posts
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QMetaType usage

    I have now sorted this out.

    Declaring a pointer to the non-Qt class as a new Meta-Type and then passing the pointer through the signal/slot connection did the trick.

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QMetaType usage

    Who's responsible for freeing the memory?
    J-P Nurmi

  5. #5
    Join Date
    Oct 2006
    Posts
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QMetaType usage

    A good point. I had to implement another signal/slot connection to free the memory that was being allocated just prior to the signal being emited. The main reason I went down this path was because the signal needed to be emitted from a callback function inside a .dll. Passing the pointer through the signal/slot connection was a little messy but it got the required information across the .dll boundary to my application which would then emit another signal to tell the .dll code to free up the memory.

    Out of interest I attempted to pass a Boost shared pointer through the connection but that didn't seem to work. Has anyone else tried passing a Boost::shared_ptr through a signal/slot connection?

Similar Threads

  1. Reducing CPU Usage
    By Kapil in forum Qt Programming
    Replies: 8
    Last Post: 3rd April 2011, 14:43
  2. QEffects.cpp usage.....
    By Naveen in forum Qt Programming
    Replies: 6
    Last Post: 11th January 2011, 11:07
  3. Qt4 XML usage
    By kandalf in forum Qt Programming
    Replies: 1
    Last Post: 21st November 2006, 20:18
  4. QList usage in place QPtrList
    By darpan in forum Qt Programming
    Replies: 2
    Last Post: 25th October 2006, 15:41
  5. Usage of the Debugger!!
    By Kapil in forum Qt Programming
    Replies: 9
    Last Post: 20th April 2006, 04:48

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.