Results 1 to 4 of 4

Thread: Q_DECLARE_METATYPE(T); error

  1. #1
    Join Date
    Jan 2014
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Q_DECLARE_METATYPE(T); error

    Hi,

    First of all, I am new to Qt and this forum. Looking forward to learn and contribute to this community!


    I followed the example code for registering user custom Qt class found in this link

    and getting this error
    C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    the error appear when I tried to use the macro Q_DECLARE_METATYPE, it seems that the compiler doesn't recognize the class Message.

    Code

    #ifndef MESSAGE_H
    #define MESSAGE_H

    #include <QString>

    class Message
    {
    public:
    Message();
    Message(const Message &other);
    ~Message();


    Message(const QString &name);

    QString getName()const;
    void setName(const QString &name);

    private:
    QString name_;


    };

    Q_DECLARE_METATYPE(Message); //Error point at here

    #endif // MESSAGE_H
    It has the default constructor, copy constructor and destructor as required or i missing something here?

    Regards
    Soon

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Q_DECLARE_METATYPE(T); error

    What is the context of the error message?
    What source file is being compiled when the error is output?

  3. #3
    Join Date
    Jan 2014
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Q_DECLARE_METATYPE(T); error

    source file

    #include "message.h"

    Message::Message()
    {
    }

    Message::Message(const Message &other)
    {
    name_=other.name_;
    }

    Message::~Message()
    {

    }

    Message::Message(const QString &name)
    {
    setName(name);
    }

    QString Message::getName() const
    {
    return name_;
    }

    void Message::setName(const QString &name)
    {
    name_ = name;
    }
    After some search on google, I had found the solution in other similar issue.. link

    it seems that i need to include a header file of QMetaType, which the tutorial didnt mention about it. Strange thing macro is still defined without the header file..

    thank anyway!

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Q_DECLARE_METATYPE(T); error

    Quote Originally Posted by SentaVera View Post
    Strange thing macro is still defined without the header file..
    It is not. Which is the error you got.

    Because the compiler saw a function declaration, function name Q_DECLARE_METATYPE, one argument of type Message, but missing return type.
    So it complained about the missing return type, said it would assume it and warning you that this is not specified standard behavior.

    Cheers,
    _

Similar Threads

  1. Avoiding Q_DECLARE_METATYPE
    By moijhd in forum Qt Programming
    Replies: 6
    Last Post: 11th July 2013, 10:09
  2. Q_DECLARE_METATYPE() questions.
    By hickscorp in forum Qt Programming
    Replies: 1
    Last Post: 29th June 2010, 16:04
  3. Problem to declare a stl map - Q_DECLARE_METATYPE
    By Althor in forum Qt Programming
    Replies: 5
    Last Post: 9th December 2008, 09:41
  4. How to use Q_DECLARE_METATYPE
    By lni in forum Qt Programming
    Replies: 6
    Last Post: 21st July 2008, 17:13
  5. Q_DECLARE_METATYPE and qVariantCanConvert
    By manojmka in forum Qt Programming
    Replies: 1
    Last Post: 1st April 2008, 06:13

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.