K. Frank
2013-02-19 13:19:18 UTC
Hello List!
Sometimes I have a simple class, maybe a POD, that I want to
pump through a queued signal-slot connection. As I understand
it, I need a QObject to do that. So I wrap my class in QObject.
What are some good idioms for this? What is the most parsimonious
approach?
Here's one method I've used:
wrapped_pod.h:
#include "pod.h"
#include <QObject>
#include <QMetaType>
class WrappedPOD : public QObject, public POD {
Q_OBJECT
public:
WrappedPOD() {}
WrappedPOD (const WrappedPOD &wp) : POD(wp) {}
WrappedPOD (const POD &p) : POD(p) {}
~WrappedPOD() {}
};
(A comment: I was a little surprised that I seem to need to define
the constructors. I would have thought that the c++ defaults would
have sufficed.)
Any thoughts on other, better ways to achieve this goal? Or is there
an approach I can use that avoids wrapping the object in the first place?
I imagine that this is not an uncommon need, so I imagine that there
is some standard practice I can learn from.
Thanks.
K. Frank
Sometimes I have a simple class, maybe a POD, that I want to
pump through a queued signal-slot connection. As I understand
it, I need a QObject to do that. So I wrap my class in QObject.
What are some good idioms for this? What is the most parsimonious
approach?
Here's one method I've used:
wrapped_pod.h:
#include "pod.h"
#include <QObject>
#include <QMetaType>
class WrappedPOD : public QObject, public POD {
Q_OBJECT
public:
WrappedPOD() {}
WrappedPOD (const WrappedPOD &wp) : POD(wp) {}
WrappedPOD (const POD &p) : POD(p) {}
~WrappedPOD() {}
};
(A comment: I was a little surprised that I seem to need to define
the constructors. I would have thought that the c++ defaults would
have sufficed.)
Any thoughts on other, better ways to achieve this goal? Or is there
an approach I can use that avoids wrapping the object in the first place?
I imagine that this is not an uncommon need, so I imagine that there
is some standard practice I can learn from.
Thanks.
K. Frank