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
QtWS25 Last Chance

QtCreator: Refactoring shreds project

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
5 Posts 4 Posters 1.5k 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.
  • 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
      0
      • 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
          1
          • 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

            • Login

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