[Qt-interest] LNK2001 after extracting an Interface

Thomas Ehrnhoefer thomas.ehrnhoefer at tasktop.com
Fri Jul 15 20:41:51 CEST 2011


Hi

I got some code working, with ClassA being being a normal class extending
QObject.
Now a new requirement came up, and I need ClassA to be turned into an
interface, and ClassAImpl to implement it.

I moved all private methods and fields to ClassAImpl, made the public
declarations virtual in ClassA and added them along with the implementation
in ClassAImpl.

When I am compiling, I get problems related to the meta object compiler:
classa.obj : error LNK2001: unresolved external symbol "public: virtual void
__thiscall ClassA::methodA(void)" (?methodA at ClassA@@UAEXXZ)

I searched for a bit and all I found was people not having the Q_OBJECT
macro, which I do. I am admitting that I am still a bit fuzzy about the meta
object model.

Would be great if anybody has some hints on what I have obviously or maybe
done wrong here. I will add some code samples at the bottom

Thanks
Thomas

*So basically ClassA looks like this:*
*classa.h*
#ifndef CLASSA_H
#define CLASSA_H
#include <QObject>

class ClassA : public QObject
{
    Q_OBJECT
public:
   ClassA(QObject *parent = 0);
public slots:
    virtual void methodA();

};

#endif // CLASSA_H

*classa.cpp*
#include "classa.h"

ClassA::ClassA(QObject *parent) :
    QObject(parent)
{
}

*And ClassAImpl like this:*

*classaimpl.h*
#ifndef CLASSAIMPL_H
#define CLASSAIMPL_H
#include "classa.h"

class ClassAImpl : public ClassA
{
    Q_OBJECT
public:
    ClassAImpl(QObject *parent = 0);
    ~ClassAImpl();
public slots:
    void methodA();
private slots:
    void privateMethodB(QString str);
private:
    QString *memberC;
};
#endif // CLASSAIMPL_H

*classaimpl.cpp*
#include "classaimpl.h"

ClassAImpl::ClassAImpl(QObject *parent) :
    ClassA(parent),
    memberC("test")
{
}

ClassAImpl::~ClassAImpl()
{
}

void ClassAImpl::methodA()
{
    memberC.append(" called");
}

void ClassAImpl::privateMethodB(QString str)
{
    memberC.append(str);
}


-- 
Thomas Ehrnhoefer
Software Developer, http://tasktop.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110715/9260abcd/attachment.html 


More information about the Qt-interest-old mailing list