[Qt-interest] LNK2001 after extracting an Interface

Jesus Fernandez jsfdez at gmail.com
Sat Jul 16 12:53:53 CEST 2011


Hi.

In the ClassA definition you need to tell the compiler that methodA is a
pure virtual method:
  *virtual void methodA() = 0;*
If not you need to provide an implementation to this method or the linker
will try to find the implementation.

On Fri, Jul 15, 2011 at 20:41, Thomas Ehrnhoefer <
thomas.ehrnhoefer at tasktop.com> wrote:

> 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
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110716/3b8541d4/attachment.html 


More information about the Qt-interest-old mailing list