JPNaude
3rd March 2010, 06:43
Hi
I use the QObject->inherits() function in a couple of places, in the one place it works but in the other place it does not and I can't figure out why.
First usage case = works
I return a list of objects which implements a specific interface. In obj the interface is declared using Q_INTERFACES, but according to the documentation inherits is not meant only for interfaces.
QString iface_type = "IConfigPage";
if (obj->inherits(meta_type.toAscii().data()))
// do some stuff
Second usage case = does not work
I filter subjects in order to allow only certain types of objects to continue past the if statement. Variable is the name of a base class in my project.
QString meta_type = "Variable";
if (obj->inherits(meta_type.toAscii().data()))
// do some stuff
Since these two are almost exactly the same, I suspect that it is related to class Variable. A simplified version of this class is shown below:
class QTSF_SHARED_EXPORT Variable : public QObject
{
Q_OBJECT
public:
explicit Variable(const QString& variableType, QObject *parent = 0);
Variable(const Variable &other);
virtual ~Variable() {};
}
and below is a variable type based on the Variable base class:
class QTSF_SHARED_EXPORT Matrix : public Variable
{
Q_OBJECT
friend class MatrixPrivate;
public:
Matrix(QObject *parent = 0);
...
...
Any ideas on why it is not working would be much appreciated.
Thanks
Jaco
I use the QObject->inherits() function in a couple of places, in the one place it works but in the other place it does not and I can't figure out why.
First usage case = works
I return a list of objects which implements a specific interface. In obj the interface is declared using Q_INTERFACES, but according to the documentation inherits is not meant only for interfaces.
QString iface_type = "IConfigPage";
if (obj->inherits(meta_type.toAscii().data()))
// do some stuff
Second usage case = does not work
I filter subjects in order to allow only certain types of objects to continue past the if statement. Variable is the name of a base class in my project.
QString meta_type = "Variable";
if (obj->inherits(meta_type.toAscii().data()))
// do some stuff
Since these two are almost exactly the same, I suspect that it is related to class Variable. A simplified version of this class is shown below:
class QTSF_SHARED_EXPORT Variable : public QObject
{
Q_OBJECT
public:
explicit Variable(const QString& variableType, QObject *parent = 0);
Variable(const Variable &other);
virtual ~Variable() {};
}
and below is a variable type based on the Variable base class:
class QTSF_SHARED_EXPORT Matrix : public Variable
{
Q_OBJECT
friend class MatrixPrivate;
public:
Matrix(QObject *parent = 0);
...
...
Any ideas on why it is not working would be much appreciated.
Thanks
Jaco