Hi,
I want to configure objects that are encapsulated in other objects using a configuration file and a plugin architecture, so I do not know in advance which objects are contained within the object. Is it possible to do this using the QObject:
roperty() function?
Example:
class BInterface {
public:
virtual ~BInterface() {}
virtual int foo() = 0;
};
class B
: public QObject,
public BInterface
{
Q_OBJECT
Q_PROPERTY(int b READ b WRITE setB );
public:
virtual ~B() {}
virtual int foo() { return mv_b; }
const int b() const { return mv_b; }
void setB( const int b ) { mv_b = b; }
private:
int mv_b;
};
Q_OBJECT
Q_PROPERTY(BInterface* B READ B WRITE setB);
public:
A() { mv_B = NULL; }
virtual ~A() { if(mv_B) delete mv_B; }
const BInterface * B() { return mv_B; }
void setB( const BInterface * B ) { if (mv_B) delete mv_B; mv_B = B; }
private:
BInterface * mv_B;
};
class BInterface {
public:
virtual ~BInterface() {}
virtual int foo() = 0;
};
class B : public QObject, public BInterface
{
Q_OBJECT
Q_PROPERTY(int b READ b WRITE setB );
public:
virtual ~B() {}
virtual int foo() { return mv_b; }
const int b() const { return mv_b; }
void setB( const int b ) { mv_b = b; }
private:
int mv_b;
};
class A : public QObject{
Q_OBJECT
Q_PROPERTY(BInterface* B READ B WRITE setB);
public:
A() { mv_B = NULL; }
virtual ~A() { if(mv_B) delete mv_B; }
const BInterface * B() { return mv_B; }
void setB( const BInterface * B ) { if (mv_B) delete mv_B; mv_B = B; }
private:
BInterface * mv_B;
};
To copy to clipboard, switch view to plain text mode
what I want to do is something like:
BInterface* b = a.property("B");
b.setProperty("b", someValue);
QObject * objA = new A();
BInterface* b = a.property("B");
b.setProperty("b", someValue);
To copy to clipboard, switch view to plain text mode
can this be done at all?
Bookmarks