QtCreator: Refactoring shreds project



  • 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?


  • Moderators

    @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.



  • @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...



  • @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 Champions 2016

    @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 ;)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.