Change Qt header inclusion style to <QDir/QHeader>
Hello, Currently Qxt source files include Qt header files with #include <QHeader>. This forces to add -I$QTDIR/include/QtCore -I$QTDIR/include/QtGui to the compiler flags.
Changing the Qt header inclusion style to <QDir/QHeader> only requires -I$QTDIR/include to the compiler flags and is easier to use for non Qmake based projects.
There are many sources that recommend this inclusion style, at least in public headers:
- http://qt-project.org/wiki/Coding-Conventions#9164ad40cbcb56ddcbb2f06d9e313803
- http://doc.qt.digia.com/qtcreator-extending/coding-style.html#including-headers
If ever you plan to accept this change request, I can provide you with a script that changes the inclusion style automatically.
Thanks
Comments (6)
-
-
reporter Hi,
Well, this contradicts what they say in the Qt Creator Coding Rules (the second link I sent you):
Including Headers
- Use the following format to include Qt headers: #include <QtCore/QWhatEver>.
- ...
All of the documents I found about Qt header inclusion style recommend the form <QModule/QHeader>. I found some more recently:
-
would probably accept an MR to change that, yes.
I generally disagree that it is needed, because not adding QXT+=core will then just result in a linker error instead of a compiler error, but i dont see the harm either.
-
Issue
#23was marked as a duplicate of this issue. -
reporter - attached fix_qt_includes.pl
Hi,
Please find attached a small script that I wrote to change the Qt and Qxt inclusion style in our source code. It's pretty simple:
% cd /path/to/source/tree % fix_qt_includes.pl --qtdir /path/to/qtdir --qxtdir /path/to/qxtdir
In this form, the script will scan the files .{c,C,cc,cpp,cxx,h,H,hpp,hxx,y,l} in the source tree recursively and will display all the include style changes to do. To actually do the changes in place*, run the command with option --rewrite:
% fix_qt_includes.pl --qtdir /path/to/qtdir --qxtdir /path/to/qxtdir --rewrite
For more help, run:
% fix_qt_includes.pl --help
The script works seamlessly. There's only a minor problem with Qt header qevent.h. Qt had the bad idea to have 2 qevent.h files:
- include/QtGui/qevent.h
- include/Qt/qevent.h
My script cannot decide the one you need and will replace the inclusion of <qevent.h> by <QtCore/QEvent> by default. Is this is not the one you need, just replace <QtCore/QEvent> by <QtGui/qevent.h> wherever it's needed.
Hope that will help you.
-
ping?
so then , when will be resolved, and also more important, this will sove
#23marked as invalid event duplicate?sdont forget mention if this will alterate how already made porjects are using qxt headers in cmake modules
- Log in to comment
Hi, I don't think so. As the header include statement of Qt Creator has been changed from <QDir/QHeader> to <QHeader> last year.