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
QString iface_type = "IConfigPage";
if (obj->inherits(meta_type.toAscii().data()))
// do some stuff
To copy to clipboard, switch view to plain text mode
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.
if (obj->inherits(meta_type.toAscii().data()))
// do some stuff
QString meta_type = "Variable";
if (obj->inherits(meta_type.toAscii().data()))
// do some stuff
To copy to clipboard, switch view to plain text mode
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() {};
}
class QTSF_SHARED_EXPORT Variable : public QObject
{
Q_OBJECT
public:
explicit Variable(const QString& variableType, QObject *parent = 0);
Variable(const Variable &other);
virtual ~Variable() {};
}
To copy to clipboard, switch view to plain text mode
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:
...
...
class QTSF_SHARED_EXPORT Matrix : public Variable
{
Q_OBJECT
friend class MatrixPrivate;
public:
Matrix(QObject *parent = 0);
...
...
To copy to clipboard, switch view to plain text mode
Any ideas on why it is not working would be much appreciated.
Thanks
Jaco
Bookmarks