PDA

View Full Version : Registering classe in QMetaType



rcintra
14th May 2007, 22:08
Hi,

I am trying to register a class on QMetaType in order to use it with QVariant. However, when I try to compile the class with the macro Q_DECLARE_METATYPE occurs an error.

Here is the code:



#include "Account.h"

Account::Account() {
// do nothing
};

Account::Account(QString _provider, QString _type, QPixmap _icon) {
provider = _provider;
type = _type;
icon = _icon;
}

Account::Account(const Account &account) {
provider = account.provider;
type = account.type;
icon = account.icon;
}

Account::~ Account() {
// do nothing
}

void Account::setProvider(QString _provider) {
provider = _provider;
}

QString Account::getProvider() {
return provider;
}

void Account::setType(QString _type) {
type = _type;
}

QString Account::getType() {
return type;
}

void Account::setIcon(QPixmap _icon) {
icon = _icon;
}

QPixmap Account::getIcon() {
return icon;
}

Q_DECLARE_METATYPE(Account)


And the error is:



Account.cpp:47: error: expected constructor, destructor, or type conversion at end of input


The error is just at the line that invokes the macro.

Any help is appreciated !

Thanks,

Rafael

wysota
14th May 2007, 22:19
Place the macro in the header file not in implementation.

rcintra
14th May 2007, 22:29
Hi wysota,

Thanks for your reply.

Actually I have already tried it, but the error seems to be the similar:



#ifndef ACCOUNT_H
#define ACCOUNT_H

#include <QPixmap>
#include <QString>


class Account {
private:
QString provider;
QString type;
QPixmap icon;

public:
Account(QString _provider, QString type, QPixmap icon);
Account();
Account(const Account &account);
~Account();
void setProvider(QString _provider);
QString getProvider();
void setType(QString _type);
QString getType();
void setIcon(QPixmap _icon);
QPixmap getIcon();
};

Q_DECLARE_METATYPE(Account)

#endif // ACCOUNT_H


And the error is:

Account.cpp:3: error: expected constructor, destructor, or type conversion before ‘Account’

Any idea?

wysota
14th May 2007, 23:05
Ok, but this doesn't reffer to this file. What does Account.cpp:3 contain? Does Account.h include <QMetaType> anywhere?

rcintra
15th May 2007, 15:09
It was missing the include <QMetaType> indeed.

Thanks a lot, wysota !

P.S. The error description could be just a little more specific...

wysota
15th May 2007, 22:26
It's very specific. Remember that it's the compiler that generates it, not Qt. So it can't know you're using an identifier that's defined in QMetaType :)