[Qt-interest] Q_DECLARE_INTERFACE trouble when using from different library

Jaco Naude naude.jaco at gmail.com
Wed Mar 31 09:54:51 CEST 2010


Hi all,

I'm stuck with a problem on Q_DECLARE_INTERFACE. I have an interface
class which is declared as an interface using Q_DECLARE_INTERFACE. I
use the interface succesfully inside the library in which it is
located. However when I link against the library and include the
interface's header file, I get the following error:

../../ObjManagementLib/source/IContext.h:47: error: expected
identifier before string constant
../../ObjManagementLib/source/IContext.h:47: error: expected ',' or
'...' before string constant
../../ObjManagementLib/source/IContext.h:47: error: expected
constructor, destructor, or type conversion before ';' token

I know what the error is saying, but don't understand why it is
happening. I've used the interface in a different library before and
there I did not have this problem.

If you can spot something wrong in the interface class below please let me know,
Any help appreciated.

Regards,
Jaco



#ifndef ICONTEXT_H
#define ICONTEXT_H

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

namespace Qtilities {
    namespace ObjManagement {
        namespace Interfaces {
            /*!
            \class IContext
            \brief Objects implementing this interface will have a
context associated with them.
              */
            class OBJMANAGEMENT_SHARED_EXPORT IContext {
            public:
                IContext() {}
                virtual ~IContext() {}

                //! Returns a context string for the context
represented by this interface.
                virtual QString contextString() const = 0;
                //! Returns a help ID for this context.
                virtual QString contextHelpId() const { return QString(); }
            };
        }
    }
}

Q_DECLARE_INTERFACE(Qtilities::ObjManagement::Interfaces::IContext,"com.Qtilities.ObjManagement.IContext/1.0");

#endif // ICONTEXT_H


where the OBJMANAGEMENT_SHARED_EXPORT macro is described as follows:


#ifndef OBJMANAGEMENT_GLOBAL_H
#define OBJMANAGEMENT_GLOBAL_H

#include <QtCore/qglobal.h>

#if defined(OBJMANAGEMENT_LIBRARY)
#  define OBJMANAGEMENT_SHARED_EXPORT Q_DECL_EXPORT
#else
#  define OBJMANAGEMENT_SHARED_EXPORT Q_DECL_IMPORT
#endif

#endif // OBJMANAGEMENT_GLOBAL_H



More information about the Qt-interest-old mailing list