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. QtCreator: Refactoring shreds project
Forum Updated to NodeBB v4.3 + New Features

QtCreator: Refactoring shreds project

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
7 Posts 6 Posters 1.6k Views 2 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.
  • J Offline
    J Offline
    J0J0
    wrote on last edited by
    #1

    Hi, I am new to Qt creator and have some trouble using "refactror" feature.

    What I want is to implement some canvas to draw on, and following (bad) advice I used a QLabel for this:

    class QLabel1 : public QLabel

    As I don't actually need label capabilities, I'd like to give some more appropriate namings and use QWidget instead of QLabel, i.e. what I am after is to refactor to

    class QCanvas1 : public QLabel

    in a 1st step, and in a 2nd step to arrive at

    class QCanvas1 : public QWidget

    What does NOT work is to use RightMouse->Refactor->RenameSymbolUnderCurser: It will only do a partial refactoring, leaving behing a broken project. In particualar, entities in the designer like "label" object of class QLabel1 (as displayed in object inspector) will NOT be renamed, ans bunch of "managed" files are not updated.

    Renaming by hand in ul_mainwindow.h to complete the partial, broken refactoring performed by QtCreator also won't work because that file is read-only.

    So what is the proper way to rename a class?

    QtCreator: 3.5.1
    Qt: 5.5.1
    OS: x86_64-linux-gnu, Ubuntu 16.04.2 LTS "xenial"
    Compiler: GCC v5.2.1

    K 1 Reply Last reply
    0
    • J J0J0

      Hi, I am new to Qt creator and have some trouble using "refactror" feature.

      What I want is to implement some canvas to draw on, and following (bad) advice I used a QLabel for this:

      class QLabel1 : public QLabel

      As I don't actually need label capabilities, I'd like to give some more appropriate namings and use QWidget instead of QLabel, i.e. what I am after is to refactor to

      class QCanvas1 : public QLabel

      in a 1st step, and in a 2nd step to arrive at

      class QCanvas1 : public QWidget

      What does NOT work is to use RightMouse->Refactor->RenameSymbolUnderCurser: It will only do a partial refactoring, leaving behing a broken project. In particualar, entities in the designer like "label" object of class QLabel1 (as displayed in object inspector) will NOT be renamed, ans bunch of "managed" files are not updated.

      Renaming by hand in ul_mainwindow.h to complete the partial, broken refactoring performed by QtCreator also won't work because that file is read-only.

      So what is the proper way to rename a class?

      K Offline
      K Offline
      koahnig
      wrote on last edited by koahnig
      #2

      @J0J0

      Hi and welcome to devnet forum

      AFAIK it is not possible to rename everything within a project. Especially things named in ui files. Most likely the reason is history of designer features with signal and slots. The auto connect feature is probably hard to distinguish and may result in broken projects as well.

      To rename stuff anything in ui_*.h is typically not a good idea. Those files are automatically generated by uic-ing process and therefore, you are going to loose your changes quickly. The safest approach is probably to rename independently in designer pane what needs to be changed.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      1
      • J Offline
        J Offline
        J0J0
        wrote on last edited by
        #3

        @koahnig

        Thaks for your swift reply.

        To rename stuff anything in ui_*.h is typically not a good idea.
        Those files are automatically generated by uic-ing process and therefore,
        you are going to loose your changes quickly.

        Indeed :-((

        The safest approach is probably to rename independently in designer
        pane what needs to be changed.

        This doen't work either because the designer doesn't feature renaming classes; it only support renaming objects.

        So the conclusion is: Don't use REFACTOR, it's broken...

        QtCreator: 3.5.1
        Qt: 5.5.1
        OS: x86_64-linux-gnu, Ubuntu 16.04.2 LTS "xenial"
        Compiler: GCC v5.2.1

        1 Reply Last reply
        0
        • aha_1980A Offline
          aha_1980A Offline
          aha_1980
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @J0J0 said in QtCreator: Refactoring shreds project:

          So the conclusion is: Don't use REFACTOR, it's broken...

          You can use refactoring, it's working nicely most of the time.. It is one case that is broken, and it is already reported as bug: https://bugreports.qt.io/browse/QTCREATORBUG-7044

          Unfortunately there is no solution yet, but you can vote for that issue to get fixed.

          I guess that also means, this thread can be closed now.

          Qt has to stay free or it will die.

          1 Reply Last reply
          2
          • mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @J0J0

            So the conclusion is: Don't use REFACTOR, it's broken...

            No, its not broken. But it do not try to replace in Ui files.

            That said, UI files are just XML files and i often use
            XMLStarlet to change values in them.
            Creator will just ask if you want to reload it.
            Just make sure its not open in Designer. ( as its then just overridden)

            Ps I have all code under code revision an hence have zero fears of changing the UI files.
            If you do not have, be gentle to it ;)

            1 Reply Last reply
            3
            • osirisgothraO Offline
              osirisgothraO Offline
              osirisgothra
              wrote last edited by
              #6

              Never use refactoring if:

              1. Your (or your team's) design methods are very different from how Qt structurizes code.
              2. Do things refactor doesnt expect like multiple inheritance (like for multiple interfaces, for example)
              3. Implement your class in some other way than the usual .h + .cpp pair (or standalone .h) for example, using many .cpp files that partially implement bits of your class which is declared in a single .h file.
              4. Have complex or deeply embedded namespaces and objects
              5. Are using newer code features than what refactor expects
              6. Are working with a very large codebase that is shared across a team

              In such cases, you should probably be writing (or have been supplied with) your own custom refactoring tools. The QtCreator refactor only provides basic refactoring for smaller projects, and is not meant to take on large tasks.

              Another option is to subdivide a project if it is getting too large. It might also be a red flag that refactor chokes on your project and could be indicative of a subtle code design problem in your project that hasn't caused you any issues just yet.

              That said, people code in many ways. Us older coders are set in them, and that's fine. However it is best not to rely too much on refactoring tools or expect them to follow your expectations alone. Personally, I still find my collection of perl scripts serve me best -- and since QtC has 'external tools' I can just keybind them to do the same stuff refactoring could do. Of course, my tools aren't gonna work for other people. Hence the confusion people get, I suppose.

              I'm truly glad you r/offmychess t finally, but please don't go too far, because you r/beyondvoxels and that implies that u r/donewithlife. Oh well time to git back to the lab, because azure sea here, I have a lot of work to do...

              Christian EhrlicherC 1 Reply Last reply
              0
              • osirisgothraO osirisgothra

                Never use refactoring if:

                1. Your (or your team's) design methods are very different from how Qt structurizes code.
                2. Do things refactor doesnt expect like multiple inheritance (like for multiple interfaces, for example)
                3. Implement your class in some other way than the usual .h + .cpp pair (or standalone .h) for example, using many .cpp files that partially implement bits of your class which is declared in a single .h file.
                4. Have complex or deeply embedded namespaces and objects
                5. Are using newer code features than what refactor expects
                6. Are working with a very large codebase that is shared across a team

                In such cases, you should probably be writing (or have been supplied with) your own custom refactoring tools. The QtCreator refactor only provides basic refactoring for smaller projects, and is not meant to take on large tasks.

                Another option is to subdivide a project if it is getting too large. It might also be a red flag that refactor chokes on your project and could be indicative of a subtle code design problem in your project that hasn't caused you any issues just yet.

                That said, people code in many ways. Us older coders are set in them, and that's fine. However it is best not to rely too much on refactoring tools or expect them to follow your expectations alone. Personally, I still find my collection of perl scripts serve me best -- and since QtC has 'external tools' I can just keybind them to do the same stuff refactoring could do. Of course, my tools aren't gonna work for other people. Hence the confusion people get, I suppose.

                Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote last edited by
                #7

                @osirisgothra what's the point of recroposting an 8 year old thread?

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                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