Results 1 to 6 of 6

Thread: Problem with QFlags and macro Q_DECLARE_FLAGS - typedef cannot be seen.

  1. #1
    Join Date
    Jun 2010
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Problem with QFlags and macro Q_DECLARE_FLAGS - typedef cannot be seen.

    Hi everyone, is there anybody who can help me with follwoing problem? I would like to use QFlags class. When compiling below code i get error.
    Qt Code:
    1. #ifndef OBJECTQ_H
    2. #define OBJECTQ_H
    3.  
    4. #include <QtCore/qglobal.h>
    5. #include <QtCore/qobject.h>
    6.  
    7. class Objectq : public QObject
    8. {
    9. public:
    10. enum MyEnum
    11. {
    12. Enum1 = 0x0,
    13. Enum2 = 0x1
    14. };
    15. Q_DECLARE_FLAGS(MyEnums, MyEnum)
    16. Objectq();
    17. MyEnums flags() const;
    18.  
    19. private:
    20. MyEnums mFlags;
    21. };
    22. Q_DECLARE_OPERATORS_FOR_FLAGS(Objectq::MyEnums);
    23.  
    24. #endif // OBJECTQ_H
    To copy to clipboard, switch view to plain text mode 

    The compiler output is following:
    Qt Code:
    1. ..\Flagi\objectq.cpp(7) : error C2143: syntax error : missing ';' before 'Objectq::flags'
    2. ..\Flagi\objectq.cpp(7) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    3. ..\Flagi\objectq.cpp(8) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    4. ..\Flagi\objectq.cpp(8) : error C2556: 'int Objectq::flags(void) const' : overloaded function differs only by return type from 'Objectq::MyEnums Objectq::flags(void) const'
    5. c:\users\lukasz\workspace\flagi\objectq.h(17) : see declaration of 'Objectq::flags'
    6. ..\Flagi\objectq.cpp(8) : error C2371: 'Objectq::flags' : redefinition; different basic types
    7. c:\users\lukasz\workspace\flagi\objectq.h(17) : see declaration of 'Objectq::flags'
    To copy to clipboard, switch view to plain text mode 

    It seems that in method MyEnums flags() const; type MyEnums isn't visible, but I don't have idea why. According to QT documentation macro Q_DECLARE_FLAGS should do the job, but it isn't. I've spent a lot of time trying to get known what's is wrong, now it's time to ask for help somone clever than me .
    Last edited by miqqo; 7th July 2010 at 22:00.

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Problem with QFlags and macro Q_DECLARE_FLAGS - typedef cannot be seen.

    The errors you posted are from the cpp file, not the header file.
    Please post the code of the cpp file.

    And please read the error messages from top to bottom. The most obvious problem (and this will reduce a lot of errors) is the missing ; at line 7

  3. #3
    Join Date
    Jun 2010
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem with QFlags and macro Q_DECLARE_FLAGS - typedef cannot be seen.

    I doubt that it is a matter a cpp file, it is very simple test class only:

    objectq.cpp:
    Qt Code:
    1. #include "objectq.h"
    2.  
    3. Objectq::Objectq()
    4. {
    5. }
    6.  
    7. MyEnums Objectq::flags() const
    8. {
    9. return mFlags;
    10. }
    To copy to clipboard, switch view to plain text mode 
    #include "objectq.h"

    Objectq::Objectq()
    {
    }

    MyEnums Objectq::flags() const
    {
    return mFlags;
    }

  4. #4
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Problem with QFlags and macro Q_DECLARE_FLAGS - typedef cannot be seen.

    Use

    Qt Code:
    1. Objectq::MyEnums
    To copy to clipboard, switch view to plain text mode 

    everywhere instead of just MyEnums.

  5. #5
    Join Date
    May 2010
    Posts
    14
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Problem with QFlags and macro Q_DECLARE_FLAGS - typedef cannot be seen.

    Don't you need to have the Q_OBJECT macro first?

  6. #6
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Problem with QFlags and macro Q_DECLARE_FLAGS - typedef cannot be seen.

    Quote Originally Posted by jkyle View Post
    Don't you need to have the Q_OBJECT macro first?
    No, flags can also be used in non QObject based classes. See the example in the QFlags documentation.

Similar Threads

  1. Q_OBJECT macro problem
    By bijan311 in forum Newbie
    Replies: 46
    Last Post: 26th March 2010, 22:21
  2. QFlags questions
    By elcuco in forum Newbie
    Replies: 3
    Last Post: 19th March 2010, 14:33
  3. typedef question
    By MarkoSan in forum Newbie
    Replies: 5
    Last Post: 29th January 2008, 08:28
  4. Storing and Retrieving a QFlags
    By darkadept in forum Qt Programming
    Replies: 3
    Last Post: 4th October 2007, 18:53
  5. Typedef quint16 on ARM and Win32
    By sgrasic in forum Qt for Embedded and Mobile
    Replies: 3
    Last Post: 16th May 2006, 22:27

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.