Results 1 to 7 of 7

Thread: Moc generates uncompilable code

  1. #1
    Join Date
    Jan 2007
    Posts
    45
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Moc generates uncompilable code

    I have a class defined inside a namespace which has properties of the type from the same namespace:

    Qt Code:
    1. // inside the included file
    2. Q_DECLARE_METATYPE(Core::Vector)
    3.  
    4. // inside particle.h
    5. namespace Core {
    6. class Particle {
    7. Q_OBJECT
    8. Q_PROPERTY(Core::Vector position READ position WRITE setPosition)
    9. public:
    10. ....
    11. };
    12. }
    To copy to clipboard, switch view to plain text mode 

    But when trying to compile I'm getting the following error:
    particle.moc|43| error: ‘staticMetaObject’ is not a member of ‘Core’

    Inside particle.moc there is the following fragment:

    Qt Code:
    1. static const QMetaObject *qt_meta_extradata_Core__Particle[] = {
    2. &Core::staticMetaObject,0
    3. };
    4.  
    5. const QMetaObject Core::Particle::staticMetaObject = {
    6. { &Body::staticMetaObject, qt_meta_stringdata_Core__Particle,
    7. qt_meta_data_Core__Particle, qt_meta_extradata_Core__Particle }
    8. };
    To copy to clipboard, switch view to plain text mode 

    This looks like wrong code. I have no idea why moc generates it.
    Thanks in advance for any help.

  2. #2
    Join Date
    Jan 2007
    Posts
    45
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Moc generates uncompilable code

    After some more experiments I've found that the problem appears when Core::Vector and Q_DECLARE_METATYPE(Core::Vector) are in different files. When they are in the same file everything compiles OK.

    Is this expected behaviour ? It seems that documentation says nothing about it.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Moc generates uncompilable code

    Quote Originally Posted by Vladimir View Post
    It seems that documentation says nothing about it.
    Not quite, it says:
    Ideally, this macro should be placed below the declaration of the class or struct. If that is not possible, it can be put in a private header file which has to be included every time that type is used in a QVariant.
    I guess the problem is that the code generated by moc doesn't include that other header file.

  4. #4
    Join Date
    Jan 2007
    Posts
    45
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Moc generates uncompilable code

    Quote Originally Posted by jacek View Post
    Not quite, it says:
    Yes, I've missed this. Thanks for pointing me to it.

    Quote Originally Posted by jacek View Post
    I guess the problem is that the code generated by moc doesn't include that other header file.
    No, .moc file is included in .cc file which includes all required headers. Moc generates a reference to Core::staticMetaObjec where it obviously should be Core::Particle::staticMetaObject. Very strange that it is related to Q_PROPERTY.

    My original goal was to put Q_DECLARE_METATYPE into different header because I want to have a subset of my API which is independent of Qt.

  5. #5
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    554
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Moc generates uncompilable code

    class Particle is not derived from QObject.

  6. #6
    Join Date
    Jan 2007
    Posts
    45
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Moc generates uncompilable code

    Quote Originally Posted by ChristianEhrlicher View Post
    class Particle is not derived from QObject.
    No, I's derived from QObject.

  7. #7
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    554
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Moc generates uncompilable code

    Quote Originally Posted by Vladimir View Post
    No, I's derived from QObject.
    Where?

    Qt Code:
    1. namespace Core {
    2. class Particle {
    3. Q_OBJECT
    4. Q_PROPERTY(Core::Vector position READ position WRITE setPosition)
    5. public:
    6. ....
    7. };
    8. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Problem closing a QMainWindow in Qt4.2
    By ian in forum Qt Programming
    Replies: 11
    Last Post: 17th October 2006, 00:49
  2. problem with linking
    By mickey in forum Qt Programming
    Replies: 49
    Last Post: 12th August 2006, 21:41

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.