Don't remove direct Qt's and std's includes

• Feb 15, 2020 - 09:18

Hi, I’m working on the engine for displaying, playing and manipulating the score in the official MoseScore mobile application, and development a new feature for the editor.
Therefore, I work with the MoseScore code everyday, and I have an important issue for me.

For development, I use the QtCreator, it’s a very cool and powerful IDE.
To help develop, the QtCreator build a code model, and due to this model they work correctly:

  • code highlighting
  • auto completion
  • code jump
  • code using
  • rename
  • and other

In order for a QtCreator to build a code model, he needs to have information about the types used, which is provided using inclusions of these types (including standard Qt and std).

There is an IDE, for example VS Code, which work due to parsing syntax and search, so they don’t need a code model, they don’t need icludes, but they do not allow the correct implementation of a number of possibilities (jump, rename, etc.)

MoseScore uses a header precompiler to speed up build, which is good.
But it is customary to remove direct includes Qt and std (for example, , and therefore the QtCreator cannot build a code model, and this is a problem for me.

Direct inclusion of types used in the file does not interfere with working with precompiled headers and does not affect the build speed. They are not inserted by the preprocessor because they are actually already inserted by precompiled header (the insert is protected by a guard). Аt the same time, gives a lot of benefits, which may or may not be used.

Also, the direct inclusion of headers gives an understanding of the organization of the code structure. For example, if in a class like Chord, if there is something like QNetworkAccessManager, or QMessageBox, etc., it means something went wrong.
Without the direct inclusion of headers, it is more difficult to see the incorrect structure of the code, because you cannot see what the class really depends on, especially if it is very large (2000-3000 and more lines of code).

Can we change the approach, and don't remove the direct inclusion of the headers Qt and std?


Or move those all into this all.h and use #include "all.h" in all the source files (needing any of them) rather than using that command line option to included at build time?
Not sure how that influences compile time and PCH though.

OTOH I also do like the idea for every source file (either .cpp or the .h with the same basename included in the former) to #include everything it directly needs and uses and that way makes every source file 'standalone', self-contained, self-documenting its pre-requisits or whatever you want to name it.

Currently also discussed in the MuseScore developers' chat on Telegram, maybe you'd want to join there?

Do you still have an unanswered question? Please log in first to post your question.