Results 1 to 2 of 2

Thread: casting object to enum in Qt

  1. #1
    Join Date
    Jan 2012
    Location
    Iran, Tehran
    Posts
    308
    Thanks
    75
    Thanked 24 Times in 21 Posts
    Qt products
    Qt4 Qt5 PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default casting object to enum in Qt

    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?

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: casting object to enum in Qt

    use int. The c# way you mentioned isnt really object orientated hierarchy either.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. The following user says thank you to amleto for this useful post:

    alizadeh91 (20th August 2012)

Similar Threads

  1. Expose enums with webkit
    By frank100 in forum Qt Programming
    Replies: 1
    Last Post: 30th June 2014, 02:16
  2. Using namespace enums in headers
    By Phlucious in forum General Programming
    Replies: 3
    Last Post: 30th November 2011, 01:28
  3. How to use enums in qml
    By nightroad in forum Qt Quick
    Replies: 0
    Last Post: 29th June 2011, 13:24
  4. Using enums in QtScript
    By Orphelic in forum Qt Programming
    Replies: 1
    Last Post: 29th November 2007, 11:55
  5. how to use enums
    By soul_rebel in forum General Programming
    Replies: 3
    Last Post: 23rd March 2006, 21:49

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.