PDA

View Full Version : casting object to enum in Qt



alizadeh91
18th August 2012, 11:42
hi everybody...
In c# i could cast object to enum and vice verse. how can i cast enum to QObject or its reverse in Qt? Is that possible??

I wanna do something like this:

//abstract class
class A
{
//pure virtual function
virtual double getValue(double value,object originUnit) = 0;
}

class B:A
{
enum BEnums{B1,B2}
....
double getValue(double value, object originUnit) //i wish object could be BEnums or something to cast it to BEnums, so i can use object oriented hierarchy.
{}
}

class C:A
{
enum CEnums{C1,C2}
......
double getValue(double value, object originUnit) //i wish object could be CEnums or something to cast it to CEnums, so i can use object oriented hierarchy.
{}

}
Depending on which class will be initializing, the argument of getValue function will be from CEnums or BEnums.
Actually i want getValue function to work with enum argument. but because the arguments are different for each classes(B,C), so i have to declare the argument with object then in class B and C implement them and cast object to corrosponding enums. any suggestions?

amleto
18th August 2012, 15:22
use int. The c# way you mentioned isnt really object orientated hierarchy either.