Misleading header names



  • I'm not sure that's even a problem but I have to ask anyway.
    Qt provides extensionless header files like Qlist or QtCore. Interesting fact is that a lot of them contain just one line:
    QObject is "#include "qobject.h"
    QApplication is "#include "qapplication.h"
    QTimer is "#include "qtimer.h"
    and so on. I don't know why this is done like that but no matter.

    My question is: why file QMetaObject does not include qmetaobject.h but includes qobjectdefs.h?
    I spent quite some time trying to figure out why I have only forward declaration of 'class QMetaEnum'.


  • Qt Champions 2016

    Hi
    In doc, it lists the header to use for a an object
    like
    Header: #include <QMetaObject>

    So using "internal" names like qapplication.h might lead to surprises like u seen with meta system.

    I guess with such big framework, some inconsistencies will exists :)


  • Moderators

    @Amomum said:

    I don't know why this is done like that but no matter.

    Because it's easier for users to #include the class names. No need to remember the separate header filenames.

    My question is: why file QMetaObject does not include qmetaobject.h but includes qobjectdefs.h?
    I spent quite some time trying to figure out why I have only forward declaration of 'class QMetaEnum'.

    That looks like a bug. Could you please submit a report to https://bugreports.qt.io/ ?




  • Qt Champions 2016

    @JKSH said:

    That looks like a bug.

    I beg to differ.

    @Amomum, if you take a peek at the documentation of QMetaObject you'll notice that QMetaEnum is only used as a return type, so by using only the forward declaration Qt developers ensured minimal number of includes. If you need to use QMetaEnum just include that header in your code, no need to burden the compiler with headers that are not needed for compilation.

    Kind regards.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.