Hi again,
I have to confess that I'm getting lost trying to do this.
I've followed the PIMPL exercise in Herb Sutter's book and come up with the VS solution I've attached to this post.
My goal is to create a subclass of QFrame which which will have a QGraphicsView among other controls. I need to be able to use this class from many applications, so a Qt Library is the way to go.
The way I see it, is that I need to use a PIMPL approach so as to hide the #include "ui_..." line so that the client of the library doesn't end up including a file not in it's search path so that it can compile.
So this is what I've done so far:
// processdesigner_impl.h
#include <QFrame>
#include "ui_processdesigner.h"
class ProcessDesignerImpl
: public QFrame{
Q_OBJECT
public:
ProcessDesignerImpl
(QWidget *parent
= 0);
~ProcessDesignerImpl();
private:
Ui::ProcessDesignerClass ui;
};
// processdesigner_impl.h
#include <QFrame>
#include "ui_processdesigner.h"
class ProcessDesignerImpl : public QFrame
{
Q_OBJECT
public:
ProcessDesignerImpl(QWidget *parent = 0);
~ProcessDesignerImpl();
private:
Ui::ProcessDesignerClass ui;
};
To copy to clipboard, switch view to plain text mode
// processdesigner_impl.cpp
#include "processdesigner_impl.h"
ProcessDesignerImpl
::ProcessDesignerImpl(QWidget *parent
){
ui.setupUi(this);
}
ProcessDesignerImpl::~ProcessDesignerImpl()
{
}
// processdesigner_impl.cpp
#include "processdesigner_impl.h"
ProcessDesignerImpl::ProcessDesignerImpl(QWidget *parent)
: QFrame(parent)
{
ui.setupUi(this);
}
ProcessDesignerImpl::~ProcessDesignerImpl()
{
}
To copy to clipboard, switch view to plain text mode
// ProcessDesigner.h
#include "processdesigner_global.h"
#include <QWidget>
class PROCESSDESIGNER_EXPORT ProcessDesigner
: public QWidget{
Q_OBJECT
public:
ProcessDesigner
(QWidget* parent
= 0);
private:
class ProcessDesignerImpl;
ProcessDesignerImpl* procDesImpl;
};
// ProcessDesigner.h
#include "processdesigner_global.h"
#include <QWidget>
class PROCESSDESIGNER_EXPORT ProcessDesigner : public QWidget
{
Q_OBJECT
public:
ProcessDesigner(QWidget* parent = 0);
private:
class ProcessDesignerImpl;
ProcessDesignerImpl* procDesImpl;
};
To copy to clipboard, switch view to plain text mode
// ProcessDesigner.cpp
#include "ProcessDesigner.h"
#include "processdesigner_impl.h"
ProcessDesigner::ProcessDesigner()
{
//procDesImpl = new ProcessDesignerImpl(parent);
}
// ProcessDesigner.cpp
#include "ProcessDesigner.h"
#include "processdesigner_impl.h"
ProcessDesigner::ProcessDesigner()
{
//procDesImpl = new ProcessDesignerImpl(parent);
}
To copy to clipboard, switch view to plain text mode
This was compiling at one point (or maybe a slight variation) but now I'm getting these errors:
Error 3 error LNK2001: unresolved external symbol "public: virtual int __thiscall ProcessDesignerImpl::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@ProcessDesignerImpl@@UAEHW4Call@QMet aObject@@HPAPAX@Z) processdesigner_impl.obj
Error 1 error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall ProcessDesignerImpl::metaObject(void)const " (?metaObject@ProcessDesignerImpl@@UBEPBUQMetaObjec t@@XZ) processdesigner_impl.obj
Error 2 error LNK2001: unresolved external symbol "public: virtual void * __thiscall ProcessDesignerImpl::qt_metacast(char const *)" (?qt_metacast@ProcessDesignerImpl@@UAEPAXPBD@Z) processdesigner_impl.obj
Error 4 fatal error LNK1120: 3 unresolved externals D:\SourceRepository\Imaging Tools\ImagingSystemTools\Debug\ProcessDesigner.dll
I'm not sure where to turn next.
Part of my confusion lies in the fact the ProcessDesigner needs to be able to be placed on another dialog, so I need to subclass it as well. If I just subclass QWidget, then I can see that I'll have to create a one-to-one mapping on every custom function I want to expose on the ProcessDesignerImpl, because if I subclass from ProcessDesignerImpl I'll be back where I started.
The real question is, how do I actually return a ProcessDesignerImpl to the client?
I was thinking about maybe casting "procDesImpl back to a basic QWidget then returning that somewhow, or maybe the key lies in the client passing "this" into the constructor of ProcessDesigner, then that pointer gets passed into ProcessDesignerImpl, then use in the setupUp line like this:
ui.setupUi(parent);
ui.setupUi(parent);
To copy to clipboard, switch view to plain text mode
First I need to resolve these linking errors in the attached solution, then decide how to proceed. Can anyone offer any suggestions?
Regards,
Steve York
Bookmarks