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. How to automatically rename (many) data members?
Forum Updated to NodeBB v4.3 + New Features

How to automatically rename (many) data members?

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
8 Posts 3 Posters 3.0k 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.
  • D Offline
    D Offline
    dave2
    wrote on 6 Feb 2019, 07:01 last edited by
    #1

    (This question is not directly related to Qt, but Qt might provide tools which help...)

    In our Qt C++ project, we would like to change the names of data members by appending a suffix to them (currently they have no suffix). For example, we would like to rename data member foo to foo_.

    Is it possible to do this automatically? Our project has about 300,000 lines of C++ code, so any manual or semi-manual solution would be impractical.

    Our environment:

    • Windows 10
    • MS Visual Studio 2015 with Update 3, 64-bit
    • Qt 5.6.2
    • Qt Creator 4.8.1

    PS: Doing this change is not my decision, so no need to tell me how stupid you may think it is.

    J 1 Reply Last reply 6 Feb 2019, 07:03
    0
    • D dave2
      6 Feb 2019, 07:01

      (This question is not directly related to Qt, but Qt might provide tools which help...)

      In our Qt C++ project, we would like to change the names of data members by appending a suffix to them (currently they have no suffix). For example, we would like to rename data member foo to foo_.

      Is it possible to do this automatically? Our project has about 300,000 lines of C++ code, so any manual or semi-manual solution would be impractical.

      Our environment:

      • Windows 10
      • MS Visual Studio 2015 with Update 3, 64-bit
      • Qt 5.6.2
      • Qt Creator 4.8.1

      PS: Doing this change is not my decision, so no need to tell me how stupid you may think it is.

      J Offline
      J Offline
      J.Hilk
      Moderators
      wrote on 6 Feb 2019, 07:03 last edited by
      #2

      hi @dave2

      since you're using QtCreator,

      • right mouse click on the the variable you want to change
      • select refactor
      • select rename symbol under curser
      • enter new name

      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
      4
      • D Offline
        D Offline
        dave2
        wrote on 6 Feb 2019, 07:48 last edited by
        #3

        The problem is: we have thousands of data members, hence the impracticality of any (semi-)manual method.

        J 1 Reply Last reply 6 Feb 2019, 07:55
        0
        • D dave2
          6 Feb 2019, 07:48

          The problem is: we have thousands of data members, hence the impracticality of any (semi-)manual method.

          J Offline
          J Offline
          J.Hilk
          Moderators
          wrote on 6 Feb 2019, 07:55 last edited by
          #4

          @dave2
          have you tried it?
          QtCreator will rename all instances of that variable.


          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.

          D 1 Reply Last reply 6 Feb 2019, 08:11
          0
          • J J.Hilk
            6 Feb 2019, 07:55

            @dave2
            have you tried it?
            QtCreator will rename all instances of that variable.

            D Offline
            D Offline
            dave2
            wrote on 6 Feb 2019, 08:11 last edited by dave2 2 Jun 2019, 08:14
            #5

            @J.Hilk Yes, I have tried it. Qt Creator will indeed rename all instanced of that variable. Very convenient for changing a few data members. The problem, as I said, is that we have thousands of data members. That is, the process would look like:

            for each instance variable:

            • right mouse click on the the variable you want to change
            • select refactor
            • select rename symbol under curser
            • enter new name

            Doing this thousands of time would take days (weeks?), would be error-prone, and... not fun.

            Instead, is there a way to rename all data members in one go? I suppose Qt Creator does not support this, but perhaps another tool?

            J J 2 Replies Last reply 6 Feb 2019, 08:34
            0
            • D dave2
              6 Feb 2019, 08:11

              @J.Hilk Yes, I have tried it. Qt Creator will indeed rename all instanced of that variable. Very convenient for changing a few data members. The problem, as I said, is that we have thousands of data members. That is, the process would look like:

              for each instance variable:

              • right mouse click on the the variable you want to change
              • select refactor
              • select rename symbol under curser
              • enter new name

              Doing this thousands of time would take days (weeks?), would be error-prone, and... not fun.

              Instead, is there a way to rename all data members in one go? I suppose Qt Creator does not support this, but perhaps another tool?

              J Offline
              J Offline
              J.Hilk
              Moderators
              wrote on 6 Feb 2019, 08:34 last edited by
              #6

              @dave2 said in How to automatically rename (many) data members?:

              Instead, is there a way to rename all data members in one go? I suppose Qt Creator does not support this, but perhaps another tool?

              I don't think there's anything like that build into QtCreator, maybe there's a plugin or something, I wouldn't know.

              You could write a small program that recursively parses all files of your project folder and replaces words. But that explodes in complexity, if you want any kind of sanity check.


              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.

              D 1 Reply Last reply 6 Feb 2019, 08:49
              0
              • J J.Hilk
                6 Feb 2019, 08:34

                @dave2 said in How to automatically rename (many) data members?:

                Instead, is there a way to rename all data members in one go? I suppose Qt Creator does not support this, but perhaps another tool?

                I don't think there's anything like that build into QtCreator, maybe there's a plugin or something, I wouldn't know.

                You could write a small program that recursively parses all files of your project folder and replaces words. But that explodes in complexity, if you want any kind of sanity check.

                D Offline
                D Offline
                dave2
                wrote on 6 Feb 2019, 08:49 last edited by
                #7

                @J.Hilk You are right: such a tool would need to understand C++, because in our project, unfortunately, data members sometimes appear also as local variables or parameters (thus causing tons of warnings "local variable/parameter hides data member"). And we are certainly not going to write a C++ parser ourselves...

                1 Reply Last reply
                0
                • D dave2
                  6 Feb 2019, 08:11

                  @J.Hilk Yes, I have tried it. Qt Creator will indeed rename all instanced of that variable. Very convenient for changing a few data members. The problem, as I said, is that we have thousands of data members. That is, the process would look like:

                  for each instance variable:

                  • right mouse click on the the variable you want to change
                  • select refactor
                  • select rename symbol under curser
                  • enter new name

                  Doing this thousands of time would take days (weeks?), would be error-prone, and... not fun.

                  Instead, is there a way to rename all data members in one go? I suppose Qt Creator does not support this, but perhaps another tool?

                  J Offline
                  J Offline
                  JKSH
                  Moderators
                  wrote on 6 Feb 2019, 09:00 last edited by JKSH 2 Jun 2019, 09:02
                  #8

                  @dave2 said in How to automatically rename (many) data members?:

                  is there a way to rename all data members in one go? I suppose Qt Creator does not support this, but perhaps another tool?

                  I'm 80% sure the answer is "no". Your use-case is very niche.

                  Doing this thousands of time would take days (weeks?), would be error-prone

                  I'd say this is faster and less error-prone than creating your own automation tool.

                  PS: Doing this change is not my decision, so no need to tell me how stupid you may think it is.

                  Tell the decision-maker that it will take weeks. If they still don't change their mind, make sure they're paying you to do the job.

                  And we are certainly not going to write a C++ parser ourselves...

                  libclang makes this kinda feasible... ;)

                  Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                  1 Reply Last reply
                  4

                  1/8

                  6 Feb 2019, 07:01

                  • Login

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