Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. A tool to remove unused header files?

A tool to remove unused header files?

Scheduled Pinned Locked Moved Qt Creator and other tools
6 Posts 4 Posters 8.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    agarny
    wrote on last edited by
    #1

    As the title says... is anyone aware of a tool (ideally, as part of Qt Creator) to remove unused header files in a CPP file?

    Cheers, Alan.

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tobias.hunger
      wrote on last edited by
      #2

      Qt Creator does not have such a tool integrated.

      There is the "iwyu clang extension":https://code.google.com/p/include-what-you-use/ that is supposed to do it, but so far I had little success with it as its output needs some changing to work well with Qt headers. It only reports headers that it recommends to be added/removed, so you will need to do the editing.

      PS: You can use the tasklist plugin of Qt Creator with a bit of scripting to make that editing a bit less painful.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        agarny
        wrote on last edited by
        #3

        Ok, I have just had a quick look (https://code.google.com/p/include-what-you-use/wiki/InstructionsForUsers) and this is still a beta tool and requires quite a few things to get it off the ground (LLVM+Clang). So, it seems to me that I might be wasting more time than anything trying to use it.

        1 Reply Last reply
        0
        • T Offline
          T Offline
          tobias.hunger
          wrote on last edited by
          #4

          I did not find it too hard to test (I tend to have a recent build of clang around;-), but the results were not really useful to me: It suggested to remove all the "QSomeThing" headers and then wanted to have a lot of some/path/qsomething.h" headers added. That caused a lot of noise which made it really hard to find the real changes.

          A bit of scripting should help here. Maybe the tool could get fixed to not complain about headers that only include others. I should look into that at some point... if I find the time for some recreational hacking that is:-)

          L 1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            Actually, in the general case, I think a tool like this should catch such "forward" headers. They are often used as general "always include this header" kind of things in projects, and often contain a lot of stuff you don't really need. However, in Qt's case, most of them are actually useful. It is nice to be able to write
            @
            #include <QString>
            @
            instead of
            @
            #include "QtCore/qstring.h"
            @
            or something like that. However, I think that the tool should suggest to replace
            @
            #include <QtCore>
            @
            with the include for QString only, if that is all you use.

            1 Reply Last reply
            0
            • T tobias.hunger

              I did not find it too hard to test (I tend to have a recent build of clang around;-), but the results were not really useful to me: It suggested to remove all the "QSomeThing" headers and then wanted to have a lot of some/path/qsomething.h" headers added. That caused a lot of noise which made it really hard to find the real changes.

              A bit of scripting should help here. Maybe the tool could get fixed to not complain about headers that only include others. I should look into that at some point... if I find the time for some recreational hacking that is:-)

              L Offline
              L Offline
              lynn young
              wrote on last edited by
              #6

              @tobias-hunger excuse me , i 'm trying to use the "include-what-you-use" with a qt project, but i failed to do that. And i didn't find any tutorial, coud u tell me how to config it please? Thank u.

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved