Results 1 to 6 of 6

Thread: A tool to remove unused header files?

  1. #1
    Join Date
    Mar 2010
    Posts
    319
    Thanks
    1
    Thanked 14 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default A tool to remove unused header files?

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: A tool to remove unused header files?

    There is no such tool. I don't see how you'd like to detect if a header file is "used" or not.

    You can have relationships between header files such as those:

    Qt Code:
    1. /* a.h */
    2. #define A 7
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. /* b.h */
    2. #ifndef A
    3. #define A 8
    4. #endif
    To copy to clipboard, switch view to plain text mode 

    and then you have:
    Qt Code:
    1. #include "a.h"
    2. #include "b.h"
    To copy to clipboard, switch view to plain text mode 
    So which ones are "used" and which are not?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Mar 2010
    Posts
    319
    Thanks
    1
    Thanked 14 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: A tool to remove unused header files?

    I would call what you gave as an example as very bad programming, but maybe that's just me?...

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: A tool to remove unused header files?

    I assure you that you daily use a lot of headers such as these.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Mar 2010
    Posts
    319
    Thanks
    1
    Thanked 14 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: A tool to remove unused header files?

    Sadly, I wouldn't be at all surprised if you were right and, in that context, I appreciate your original comment.

    Otherwise, someone pointed me to https://code.google.com/p/include-what-you-use/. I wonder how that (beta) tool would handle your example...

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: A tool to remove unused header files?

    No idea. However no tool will be able to detect that both files are needed as when a.h is present then b.h is not needed but once you remove a.h (or better yet have an ifndef there as well) b.h (or equivalent) is required despite the fact it is not used originally. It becomes even more complex with:

    Qt Code:
    1. #ifdef Q_OS_UNIX
    2. #include "a.h"
    3. #endif
    4. #include "b.h"
    To copy to clipboard, switch view to plain text mode 

    I'm sure I can find myrriads of other examples when such automatic cleanup would fail. Sorry but no tool can replace the process of thinking about what one's doing.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Header Files
    By Maluko_Da_Tola in forum Newbie
    Replies: 1
    Last Post: 2nd October 2010, 12:04
  2. Replies: 2
    Last Post: 30th September 2010, 12:26
  3. Remove unused points from a QPainterPath
    By JaV0 in forum Qt Programming
    Replies: 0
    Last Post: 4th March 2010, 08:35
  4. How to add a tool button to a qlistview header
    By kalos80 in forum Qt Programming
    Replies: 2
    Last Post: 31st July 2008, 10:13
  5. header files not getting included
    By nimmyj in forum Installation and Deployment
    Replies: 1
    Last Post: 19th December 2006, 06:18

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.