Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-132439

QDebug includes too much (=> public header shouldn't include it?)

XMLWordPrintable

    • Icon: Suggestion Suggestion
    • Resolution: Unresolved
    • Icon: Not Evaluated Not Evaluated
    • None
    • 6.9
    • Core: I/O
    • None

      qdebug.h includes a ton of headers from Qt and the C++ standard library. That cost is basically imposed on anything that includes qdebug.h. Although Qt includes a lot of the standard library on its own (just QList/QString/QVariant alone will end up including <functional>, <algorithm>, <string>, <string_view>, <memory>, <type_traits>, <vector>, <variant>...), qdebug.h goes maybe a bit overboard:

      #include <array>
      #include <chrono>
      #include <list>
      #include <map>
      #include <memory>
      #include <optional>
      #include <set>
      #include <string>
      #include <string_view>
      #include <set>
      #include <tuple>
      #include <QtCore/q20type_traits.h>
      #include <unordered_map>
      #include <unordered_set>
      #include <utility>
      #include <unordered_map>
      #include <unordered_set>
      #include <vector>
      

      We don't have a good solution for this, such as isolate the streaming operators of C++ types in another header. (A very similar issue exists with qhash.h and the hashers for standard library types.)

      However, we have some public headers that include qdebug.h. That means that now including those headers will pull in half of the STL. The heaviest offender is qvariant.h, but a quick search reveals more:

      corelib/kernel/qcoreapplication.h
      19:#include <QtCore/qdebug.h>
      
      network/socket/qlocalsocket.h
      12:#include <QtCore/qdebug.h>
      
      network/socket/qabstractsocket.h
      17:#include <QtCore/qdebug.h>
      
      gui/math3d/qgenericmatrix.h
      9:#include <QtCore/qdebug.h>
      
      corelib/kernel/qvariant.h
      12:#include <QtCore/qdebug.h>
      

      Should we try and avoid including qdebug.h from any public header?

        For Gerrit Dashboard: QTBUG-132439
        # Subject Branch Project Status CR V

            ahmad.samir Ahmad Samir
            peppe Giuseppe D'Angelo
            Vladimir Minenko Vladimir Minenko
            Alex Blasche Alex Blasche
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: