Results 1 to 8 of 8

Thread: How to write an enum in order QtCreator gives me 'auto' when use ::

  1. #1
    Join Date
    Sep 2010
    Posts
    654
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    56
    Thanked 1 Time in 1 Post

    Default How to write an enum in order QtCreator gives me 'auto' when use ::

    I have a class with a public enum declared at .h. for example myenum.
    Into implementation I want to have a way to 'view' myenum elements.
    Need I to define I namespace ? Use myenum:: gives me nothing.
    Any idea? (maybe it is a very basic question....)
    Thanks

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 334 Times in 317 Posts

    Default Re: How to write an enum in order QtCreator gives me 'auto' when use ::

    If you use some good IDE, I guess you can see those values through auto completion.

  3. #3
    Join Date
    Apr 2011
    Location
    Switzerland
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to write an enum in order QtCreator gives me 'auto' when use ::

    With the following class definition, using the class name MyClass:: lists the enumerators eZero, eOne, eTwo. ( use ctrl-SPACE to start auto completion)

    Qt Code:
    1. class MyClass {
    2. public:
    3. enum eMyEnum { eZero, eOne, eTwo };
    4. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Sep 2010
    Posts
    654
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    56
    Thanked 1 Time in 1 Post

    Default Re: How to write an enum in order QtCreator gives me 'auto' when use ::

    Thanks.
    The problem is that ctr space offers me a lot of function and members. I'd want to see only the enum values I want.
    If I know that I want values for a specific enum it must be exists a way to do it.... but I dont know how to.

  5. #5
    Join Date
    Apr 2011
    Posts
    124
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows Symbian S60
    Thanks
    1
    Thanked 10 Times in 10 Posts

    Default Re: How to write an enum in order QtCreator gives me 'auto' when use ::

    I think you want too much.

    Enums have never fit smoothly into C/C++ (or Java, or most other languages). The enum name in C/C++ is pretty meaningless -- for the most part just syntactic sugar. Some versions of Pascal did it a bit differently, but it still was awkward.

    Probably about the best you can do is embed the enum in its own class (possibly as an inner class in languages that allow it). Or "smarten" your IDE somehow so that it will know that Ctrl-E means "show me the next enum".

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: How to write an enum in order QtCreator gives me 'auto' when use ::

    The declaration of an enum in C++ does not create a new naming scope as, for example, declaring a new class or struct does. There is no MyEnum::Value. The enum values become members of the scope that contains the enum declaration and that is what every code completion tool I have seen shows (and certainly what every C++ compiler does when resolving these names). So, for example, you cannot compile this:
    Qt Code:
    1. struct Test {
    2. enum OneType { One, Two, Three };
    3. enum AnotherType { Three, Four, Five };
    4. OneType one;
    5. AnotherType another;
    6. };
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. $ g++ -c main.cpp
    2. main.cpp:3: error: declaration of ‘Three’
    3. main.cpp:2: error: conflicts with previous declaration ‘Test::OneType Test::Three’
    To copy to clipboard, switch view to plain text mode 

    You can wrap your enums in classes to also gain type safety, but a typical approach to this using templates, also breaks some code completion implementations (e.g. Qt Creator).
    http://en.wikibooks.org/wiki/More_C%...Type_Safe_Enum

  7. #7
    Join Date
    Mar 2011
    Location
    Denmark
    Posts
    74
    Qt products
    Qt4
    Platforms
    MacOS X Windows
    Thanks
    7
    Thanked 10 Times in 9 Posts

    Default Re: How to write an enum in order QtCreator gives me 'auto' when use ::

    In general I use the following naming convention for enums:

    Qt Code:
    1. enum STATUS { STATUS_GOOD, STATUS_BAD };
    To copy to clipboard, switch view to plain text mode 
    This provides the following perks:
    - when the autocomplete pops up for my class I know what is an enum because its all caps
    - when the autocomplete pops up the values of the enum are grouped together because of the prefix
    - name clashes are also prevented because of the prefix

  8. The following user says thank you to Berryblue031 for this useful post:

    tonnot (29th April 2011)

  9. #8
    Join Date
    Sep 2010
    Posts
    654
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    56
    Thanked 1 Time in 1 Post

    Default Re: How to write an enum in order QtCreator gives me 'auto' when use ::

    Thanks to everybody.
    I already are using a naming convention as BerryBlue said.

Similar Threads

  1. Replies: 0
    Last Post: 23rd March 2011, 11:34
  2. How to use QVariant with enum?
    By FinderCheng in forum Qt Programming
    Replies: 1
    Last Post: 25th December 2010, 22:23
  3. Replies: 2
    Last Post: 2nd November 2010, 06:15
  4. i want write TOrrent client on QTCreator
    By nhs_0702 in forum Qt Programming
    Replies: 0
    Last Post: 26th March 2010, 08:32
  5. Replies: 2
    Last Post: 8th November 2009, 06:30

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.