1

I'm follow Qt Echo Plugin example and trying to write complex application. My project have following structure:

MainDir \
    Main.pro
    kernel \
        kernel.pro
        abstractinterface.h
        main.cpp
    testplugin \
        testplugin.pro
        abstractplugin.h
        abstractplugin.cpp

Problem is in plugin header file:

#include <QObject>
#include <QtPlugin>
#include "abstractinterface.h"

class AbstractPlugin : public QObject, AbstractInterface
// An error appears here
// expected class-name before '{' token
{
    Q_OBJECT
    //... plugin initialization code ...
public:
    explicit AbstractPlugin(QObject *parent = 0);
};

Also, autocompletion can't find class AbstractInterface.

So, question is: what I'm doing wrong? In testplugin.pro file I have line INCLUDEPATH += ../kernel/.

Any help appreciated.

---- EDIT -----
abstractinterface.h

#include <QtPlugin>

#define INTERFACE_ID "AbstractInterface/1.0"

class AbstractInterface
{
public:
    virtual ~AbstractInterface();


    virtual void init();
    virtual void enable();
    virtual void disable();
};

Q_DECLARE_INTERFACE(AbstractInterface, INTERFACE_ID)
László Papp
  • 51,870
  • 39
  • 111
  • 135
Ivan
  • 490
  • 1
  • 7
  • 23
  • If there is no error on including the file abstractinterface.h then please check if the name AbstractInterface is correct or maybe it is within some namespace which you missed. Also make your class explicitly derived as public otherwise it is not clear why AbstractInterface must be there: public QObject, public AbstractInterface. – Alexander V Dec 05 '14 at 01:44
  • Please show `abstractinterface.h`. – László Papp Dec 05 '14 at 06:55
  • 1
    @Ivan: that looks right. I think your problem is this: `INCLUDEPATH += ../kernel/`. Try `INCLUDEPATH += $$PWD/../kernel/`. You likely execute qmake from the project root, but that would mean you did not give us all the error messages!! – László Papp Dec 05 '14 at 08:01

1 Answers1

2

Given that your pasted files look correct and work here, I am leaning towards that your problem is this line:

INCLUDEPATH += ../kernel/

You likely execute qmake from the project root where your main project file resides calling qmake recursively to generate the Makefiles. However, at the point of generation, the aforementioned path will extend from the project root rather than from the sub-directory. Please fix your testplugin.pro project file by using this instead:

INCLUDEPATH += $$PWD/../kernel/

However, what is even better design is to not handle it inside that project file, but the other kernel.pro where the header files reside. It is more flexible design to add this in there:

INCLUDEPATH += $$PWD

Edit: Based on your comment which was not in the original question, it seems that you have another problem. You seem to have messed with the include guards called the same in two different files and that is why the second inclusion did not result in providing the accessibility for you.

László Papp
  • 51,870
  • 39
  • 111
  • 135
  • Sorry, this is was my bad. I'll describe problem in answer. – Ivan Dec 05 '14 at 13:07
  • Ok. Problem was in my mind. First of all I named my iterface class as plugin and file with interface in module kernel was abstractplugin.h. But then I rename it to abstractinterface.h and create module testplugin. But I forget to rename preprocessor directive #define, which QtCreator automatically generate. Problem appear when I create plugin class and named it abstractplugin.h. Preprocessor generate same variable for new file and when I include interface, it shadows and programm was unable to found it. Sorry for my English. Think explained clearly :) – Ivan Dec 05 '14 at 13:15
  • @Ivan: OK, I think I understand. That issue was not mentioned in the question. I updated the answer. Please note that the advice is still valid for the includepath, however. So you need to solve both issues. – László Papp Dec 05 '14 at 13:25
  • It's soloved, but answer in comments and I can't mark it as "Answer". – Ivan Dec 09 '14 at 15:22