PDA

View Full Version : Q_DECLARE_METATYPE(T); error



SentaVera
2nd January 2014, 07:33
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 (http://qt-project.org/doc/qt-4.8/custom-types.html)

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

ChrisW67
2nd January 2014, 07:49
What is the context of the error message?
What source file is being compiled when the error is output?

SentaVera
2nd January 2014, 07:59
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 (http://www.qtforum.org/article/25606/strange-compile-error-using-q-declare-metatype.html?7045c938#post90264)

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! :)

anda_skoa
2nd January 2014, 15:40
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,
_