Mike
29th May 2006, 21:25
Hi,
I'm using QT 4.1 and can't explain the following problem. I have a method that does return either Class1 or Class2. Both inherit QObject. If I read the manual correct, than the following should result in null, but it doesn't:
...
public class Class1 : public QObject
{
...
};
public class Class2 : public QObject
{
...
};
public QObject* GetSomeData()
{
return new Class2();
}
....
// Somewhere I invoke the method above and would like
// to check if the method returned Class1 or Class2...
QObject* response = GetSomeData();
Class1* classOne = qobject_cast<Class1*>(response);
if (classOne)
{
// Method returned instance of class 1
...
}
So the problem I have in my code, is that qobject_cast never results in a null pointer... So the following if condition does allways execute... however the documentation does say something else. Anybody seen this too?
Regards,
Michael
I'm using QT 4.1 and can't explain the following problem. I have a method that does return either Class1 or Class2. Both inherit QObject. If I read the manual correct, than the following should result in null, but it doesn't:
...
public class Class1 : public QObject
{
...
};
public class Class2 : public QObject
{
...
};
public QObject* GetSomeData()
{
return new Class2();
}
....
// Somewhere I invoke the method above and would like
// to check if the method returned Class1 or Class2...
QObject* response = GetSomeData();
Class1* classOne = qobject_cast<Class1*>(response);
if (classOne)
{
// Method returned instance of class 1
...
}
So the problem I have in my code, is that qobject_cast never results in a null pointer... So the following if condition does allways execute... however the documentation does say something else. Anybody seen this too?
Regards,
Michael