PDA

View Full Version : Q_DECLARE_INTERFACE and namespaces



JPNaude
20th January 2010, 12:17
Hi

I get the following error in regard to the interface below:



In file included from ../tmp/../source/IView.h:24,
from ../tmp/moc_IView.cpp:10:
../tmp/../source/IContext.h:42: error: expected identifier before string constant


This is my class:



#ifndef ICONTEXT_H
#define ICONTEXT_H

#include "ObjManagement_global.h"
#include <QString>

namespace Qtilities {
namespace ObjManagement {
namespace Interfaces {
class OBJMANAGEMENT_SHARED_EXPORT IContext {
public:
virtual QString context() const = 0;
virtual QString contextHelpId() const { return QString(); }
};
}
}
}

Q_DECLARE_INTERFACE(Qtilities::ObjManagement::Inte rfaces::IContext,"com.Qtilities.ObjManagement.IContext/1.0")

#endif // ICONTEXT_H


The interface is used in another interface, which class can inherit from and then implement IContext. This class is shown below:



#ifndef IVIEW_H
#define IVIEW_H

#include "ObjManagement_global.h"
#include "IContext.h"

#include <QWidget>

namespace Qtilities {
namespace ObjManagement {
namespace Interfaces {
class OBJMANAGEMENT_SHARED_EXPORT IView : public QWidget, virtual public IContext
{
Q_OBJECT
Q_INTERFACES(Qtilities::ObjManagement::Interfaces: :IContext)

public:
IView(QWidget * parent = 0, Qt::WindowFlags f = 0) : QWidget(parent,f) {}
virtual ~IView() {}

signals:
void appendContext(const QString& context);
void removeContext(const QString& context);
};
}
}
}

#endif // IVIEW_H


I suspect it has something to do with the namespaces? It has worked before but stopped working now and I can't figure out what changed.

Any inputs will be appreciated.

Thanks.
Jaco

wysota
22nd January 2010, 12:08
Did you try declaring the interface inside the namespace?


namespace ... {
class X ... { ... };
Q_DECLARE_INTERFACE(X, "...");
}

Alternatively you can just make your class inherit QObject and add Q_OBJECT macro, you won't need Q_DECLARE_INTERFACE then.

sriky27
5th April 2011, 16:39
Did you try declaring the interface inside the namespace?


namespace ... {
class X ... { ... };
Q_DECLARE_INTERFACE(X, "...");
}

Alternatively you can just make your class inherit QObject and add Q_OBJECT macro, you won't need Q_DECLARE_INTERFACE then.

This worked for me


namespace ... {
class X ... { ... };

}
using namespace ..;
Q_DECLARE_INTERFACE(X, "...");