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. Getters/setters added twice
QtWS25 Last Chance

Getters/setters added twice

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
4 Posts 3 Posters 124 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.
  • A Offline
    A Offline
    angela2016
    wrote on 5 Mar 2025, 01:19 last edited by
    #1

    Hi,

    I used to use a rather old version of Qt Creator for a long time and when you right clicked on a member variable - "Refactor" the "Generate getter/setter" button would only be available if there wasn't a getter/setter for that variable, which made sense.

    Now with version 15.0.0 this is no longer the case, so that if there already is a getter, it will just be added twice, and then I have to delete it again, which is very annoying.

    Is there any way to recreate the way it worked before? Thanks.

    Best wishes,
    Angela

    J 1 Reply Last reply 5 Mar 2025, 07:03
    0
    • A angela2016
      5 Mar 2025, 01:19

      Hi,

      I used to use a rather old version of Qt Creator for a long time and when you right clicked on a member variable - "Refactor" the "Generate getter/setter" button would only be available if there wasn't a getter/setter for that variable, which made sense.

      Now with version 15.0.0 this is no longer the case, so that if there already is a getter, it will just be added twice, and then I have to delete it again, which is very annoying.

      Is there any way to recreate the way it worked before? Thanks.

      Best wishes,
      Angela

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 5 Mar 2025, 07:03 last edited by
      #2

      @angela2016 Could be a regression, worth reporting on Qt Bug Tracker.

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

      A 1 Reply Last reply 5 Mar 2025, 11:38
      0
      • J jsulm
        5 Mar 2025, 07:03

        @angela2016 Could be a regression, worth reporting on Qt Bug Tracker.

        A Offline
        A Offline
        angela2016
        wrote on 5 Mar 2025, 11:38 last edited by
        #3

        I looked at the source code and found the problem. In "cppcodegenerationquickfixes.cpp", "findExistingFunctions": apparently the idea is to get all possible getter/setter names including the custom ones and then compare the lowercase version of it with the lowercase version of the member functions. But "settings->getSetterName(lowerBaseName)" doesn't actually return a lowercase version of the name, so the comparison doesn't work.

        I changed the code to this and it seems to work now. Guess I'll work with my own compiled Qt Creator then.

        static void findExistingFunctions(ExistingGetterSetterData &existing, QStringList memberFunctionNames)
        {
            const CppQuickFixSettings *settings = CppQuickFixProjectsSettings::getQuickFixSettings(
                ProjectExplorer::ProjectTree::currentProject());
            const QString lowerBaseName = memberBaseName(existing.memberVariableName).toLower();
            const QStringList getterNames{lowerBaseName,
                                          "get_" + lowerBaseName,
                                          "get" + lowerBaseName,
                                          "is_" + lowerBaseName,
                                          "is" + lowerBaseName,
                                          settings->getGetterName(lowerBaseName).toLower()}; //changed from settings->getGetterName(lowerBaseName)};
            const QStringList setterNames{"set_" + lowerBaseName,
                                          "set" + lowerBaseName,
                                          settings->getSetterName(lowerBaseName).toLower()}; //changed;
            const QStringList resetNames{"reset_" + lowerBaseName,
                                         "reset" + lowerBaseName,
                                         settings->getResetName(lowerBaseName).toLower()};//changed;
            const QStringList signalNames{lowerBaseName + "_changed",
                                          lowerBaseName + "changed",
                                          settings->getSignalName(lowerBaseName).toLower()};//changed;
            for (const auto &memberFunctionName : memberFunctionNames) {
                const QString lowerName = memberFunctionName.toLower();
                if (getterNames.contains(lowerName))
                    existing.getterName = memberFunctionName;
                else if (setterNames.contains(lowerName))
                    existing.setterName = memberFunctionName;
                else if (resetNames.contains(lowerName))
                    existing.resetName = memberFunctionName;
                else if (signalNames.contains(lowerName))
                    existing.signalName = memberFunctionName;
            }
        }
        

        Can't believe none of us camel case people ever complained about this. :)

        S 1 Reply Last reply 5 Mar 2025, 18:03
        1
        • A angela2016
          5 Mar 2025, 11:38

          I looked at the source code and found the problem. In "cppcodegenerationquickfixes.cpp", "findExistingFunctions": apparently the idea is to get all possible getter/setter names including the custom ones and then compare the lowercase version of it with the lowercase version of the member functions. But "settings->getSetterName(lowerBaseName)" doesn't actually return a lowercase version of the name, so the comparison doesn't work.

          I changed the code to this and it seems to work now. Guess I'll work with my own compiled Qt Creator then.

          static void findExistingFunctions(ExistingGetterSetterData &existing, QStringList memberFunctionNames)
          {
              const CppQuickFixSettings *settings = CppQuickFixProjectsSettings::getQuickFixSettings(
                  ProjectExplorer::ProjectTree::currentProject());
              const QString lowerBaseName = memberBaseName(existing.memberVariableName).toLower();
              const QStringList getterNames{lowerBaseName,
                                            "get_" + lowerBaseName,
                                            "get" + lowerBaseName,
                                            "is_" + lowerBaseName,
                                            "is" + lowerBaseName,
                                            settings->getGetterName(lowerBaseName).toLower()}; //changed from settings->getGetterName(lowerBaseName)};
              const QStringList setterNames{"set_" + lowerBaseName,
                                            "set" + lowerBaseName,
                                            settings->getSetterName(lowerBaseName).toLower()}; //changed;
              const QStringList resetNames{"reset_" + lowerBaseName,
                                           "reset" + lowerBaseName,
                                           settings->getResetName(lowerBaseName).toLower()};//changed;
              const QStringList signalNames{lowerBaseName + "_changed",
                                            lowerBaseName + "changed",
                                            settings->getSignalName(lowerBaseName).toLower()};//changed;
              for (const auto &memberFunctionName : memberFunctionNames) {
                  const QString lowerName = memberFunctionName.toLower();
                  if (getterNames.contains(lowerName))
                      existing.getterName = memberFunctionName;
                  else if (setterNames.contains(lowerName))
                      existing.setterName = memberFunctionName;
                  else if (resetNames.contains(lowerName))
                      existing.resetName = memberFunctionName;
                  else if (signalNames.contains(lowerName))
                      existing.signalName = memberFunctionName;
              }
          }
          

          Can't believe none of us camel case people ever complained about this. :)

          S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 5 Mar 2025, 18:03 last edited by
          #4

          @angela2016 Nice catch !

          Since you found the bug and the fix, please submit a patch :-)

          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
          0

          1/4

          5 Mar 2025, 01:19

          • Login

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