Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Delete unused c++ files from the project
Forum Update on Monday, May 27th 2025

Delete unused c++ files from the project

Scheduled Pinned Locked Moved Unsolved General and Desktop
17 Posts 7 Posters 3.3k Views
  • 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.
  • K Offline
    K Offline
    Kent-Dorfman
    wrote on 6 Jun 2019, 14:55 last edited by
    #5

    The .pro file should contain a list of all the needed project files. parse it and delete whatever is not referenced therein...

    1 Reply Last reply
    1
    • R Offline
      R Offline
      rockon209
      wrote on 7 Jun 2019, 05:43 last edited by
      #6

      @Kent-Dorfman
      I am not using qmake in my project i have cmake files. Thats why i dont have .pro file

      J 1 Reply Last reply 7 Jun 2019, 06:36
      0
      • R rockon209
        6 Jun 2019, 14:52

        @Kent-Dorfman
        @Qt-Champions-2018
        No not MOC files, normal C++ files(.cpp and .h) that are not used now in the project at all. In my project i have lot of these files which are in import but not used at all.
        There are also some cases that one files is used in another file but this another file is not used anywehere. So doing this manually will take a lot of time. So a script can be used. That why i need a script to do this.

        K Offline
        K Offline
        kshegunov
        Moderators
        wrote on 7 Jun 2019, 06:07 last edited by
        #7

        @rockon209 said in Delete unused c++ files from the project:

        @Qt-Champions-2018

        Don't do that. People don't appreciate being summoned. If they have something to say, they're going to post their thoughts on their own.

        Read and abide by the Qt Code of Conduct

        1 Reply Last reply
        1
        • R rockon209
          7 Jun 2019, 05:43

          @Kent-Dorfman
          I am not using qmake in my project i have cmake files. Thats why i dont have .pro file

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 7 Jun 2019, 06:36 last edited by
          #8

          @rockon209 You can parse cmake files as well.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • R Offline
            R Offline
            rockon209
            wrote on 7 Jun 2019, 07:46 last edited by
            #9

            but my Cmake file dont have the c++ files included in it. It just give the path of the folder where the files are and this folder I have all the files which are not in used also.

            A J 2 Replies Last reply 7 Jun 2019, 08:11
            0
            • R rockon209
              7 Jun 2019, 07:46

              but my Cmake file dont have the c++ files included in it. It just give the path of the folder where the files are and this folder I have all the files which are not in used also.

              A Offline
              A Offline
              aha_1980
              Lifetime Qt Champion
              wrote on 7 Jun 2019, 08:11 last edited by
              #10

              @rockon209 So how do you know a file is "unused"? If you don't have a way to know that, that will be a very hard task to write such a script.

              Qt has to stay free or it will die.

              1 Reply Last reply
              2
              • R Offline
                R Offline
                rockon209
                wrote on 7 Jun 2019, 08:15 last edited by
                #11

                My logic was to take each class name form each file cpp and search for it and if it us used in any other file then its used. Same as search function. But i dont know if its a right approach to do it. Just an intial idea i can think of.

                1 Reply Last reply
                0
                • R rockon209
                  7 Jun 2019, 07:46

                  but my Cmake file dont have the c++ files included in it. It just give the path of the folder where the files are and this folder I have all the files which are not in used also.

                  J Offline
                  J Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on 7 Jun 2019, 08:16 last edited by
                  #12

                  @rockon209 Shouldn't you as developer know which files are used and which not?
                  And why do you actually have unused files in your project?

                  What you can do: build your project and analyse the build log to see which files were compiled, remove all files which were not compiled.

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • R Offline
                    R Offline
                    rockon209
                    wrote on 7 Jun 2019, 08:20 last edited by
                    #13

                    Well I am not the only developer, there are many other developer doing the develpment for there specific part assign to them.
                    ya but in build i am not sure if all the files are build. I mean let say in a Phone we have lot of application which are used and those application are not build everytime. I am not sure just guessing

                    J J 2 Replies Last reply 7 Jun 2019, 08:33
                    0
                    • R rockon209
                      7 Jun 2019, 08:20

                      Well I am not the only developer, there are many other developer doing the develpment for there specific part assign to them.
                      ya but in build i am not sure if all the files are build. I mean let say in a Phone we have lot of application which are used and those application are not build everytime. I am not sure just guessing

                      J Offline
                      J Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on 7 Jun 2019, 08:33 last edited by
                      #14

                      @rockon209 Well, then you will need to collect build logs for all supported platforms and analyse all of them.

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • R rockon209
                        7 Jun 2019, 08:20

                        Well I am not the only developer, there are many other developer doing the develpment for there specific part assign to them.
                        ya but in build i am not sure if all the files are build. I mean let say in a Phone we have lot of application which are used and those application are not build everytime. I am not sure just guessing

                        J Offline
                        J Offline
                        J.Hilk
                        Moderators
                        wrote on 7 Jun 2019, 09:10 last edited by
                        #15

                        @rockon209
                        if you're using QtCreator,

                        you can right click on a class definition, and select open include-hierachy, should help you.

                        But I don't think that it will show stuff that is OS-Dependend - if the includes are wrapped inside #if defined(Q_OS_WIN) #endif blocks


                        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                        Q: What's that?
                        A: It's blue light.
                        Q: What does it do?
                        A: It turns blue.

                        1 Reply Last reply
                        0
                        • R Offline
                          R Offline
                          rockon209
                          wrote on 11 Jun 2019, 12:48 last edited by rockon209 6 Nov 2019, 12:49
                          #16

                          open include hierachy its a fucntion in Qt, i want to write a python script which will find it.
                          Its like to find the dead code in the project which is not been used.

                          1 Reply Last reply
                          0
                          • S Offline
                            S Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on 11 Jun 2019, 17:33 last edited by
                            #17

                            Hi,

                            Then in your script you'll have to parse all your sources, build a list of the include statements contained in all headers and implementation files, build a list of all the header/implementation files and then compare both and delete the files that do not appear in the list of include statements.

                            Interested in AI ? www.idiap.ch
                            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                            1 Reply Last reply
                            1

                            14/17

                            7 Jun 2019, 08:33

                            • Login

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