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. little bug when creating Q_OBJECT C++ classes

little bug when creating Q_OBJECT C++ classes

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
11 Posts 4 Posters 382 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.
  • G Offline
    G Offline
    Groundbounce
    wrote on last edited by
    #1

    If I create a C++ based on the Q_OBJECT I have a little problem. I add a Q_PROPERTY with myVariable name. Then I do refactor->create missing members.

    Then I compile and get an error in some C++ file starting with moc_"my class name". The error is that setMyVariable or setmyVariable does not exist. Essentially it's an issue with code that is automatically generated. The "convention" is to name a variable or function with the first word in the name starting lower case and any further words capitalized. Because functions are automatically generated by putting a word in front of the variable name, in one instance the first word of the variable name is capitalized as it is now the second word and in the other case this is missed.

    I don't know if there is a better place to report bugs?

    JoeCFDJ 1 Reply Last reply
    0
    • G Groundbounce

      If I create a C++ based on the Q_OBJECT I have a little problem. I add a Q_PROPERTY with myVariable name. Then I do refactor->create missing members.

      Then I compile and get an error in some C++ file starting with moc_"my class name". The error is that setMyVariable or setmyVariable does not exist. Essentially it's an issue with code that is automatically generated. The "convention" is to name a variable or function with the first word in the name starting lower case and any further words capitalized. Because functions are automatically generated by putting a word in front of the variable name, in one instance the first word of the variable name is capitalized as it is now the second word and in the other case this is missed.

      I don't know if there is a better place to report bugs?

      JoeCFDJ Offline
      JoeCFDJ Offline
      JoeCFD
      wrote on last edited by
      #2

      @Groundbounce Better to show some code about how Property is applied.

      1 Reply Last reply
      0
      • Christian EhrlicherC Christian Ehrlicher moved this topic from General and Desktop on
      • G Offline
        G Offline
        Groundbounce
        wrote on last edited by
        #3

        I start typing Q_PROPERTY and the Qt IDE suggests the standard list of variable and functions, I hit enter, I set the variable type to int and the variable name to myVariable.

        Then I right click Q_PROPERTY and select refactor->create missing members, I then build the empty project with the empty class and the error around the exact spelling of setmyVariable() or setMyVariable are reported by the compiler in the moc_myclass.cpp file. This file is not created by me and is not in my source directory, it is auto generated and put into the build directory, I assume it deals with signals etc for me.

        1 Reply Last reply
        0
        • J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          I remember having some similar issues in previous QtCreator versions.
          Are you up to date with your QtCreator? what version are you using?


          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
          0
          • G Offline
            G Offline
            Groundbounce
            wrote on last edited by Groundbounce
            #5

            Version 15.01. I always install updates.

            I take it the warnings about the moc_.... file not being part of the project is nothing to worry about.

            1 Reply Last reply
            0
            • G Offline
              G Offline
              Groundbounce
              wrote on last edited by
              #6

              I think I have the answer: https://cmake.org/cmake/help/latest/manual/cmake-qt.7.html#automoc

              So if I am guessing correctly cmake is doing something for Qt in generating code and the Qt IDE is doing another part. They don't both follow the same convention....

              Christian EhrlicherC 1 Reply Last reply
              0
              • G Groundbounce

                I think I have the answer: https://cmake.org/cmake/help/latest/manual/cmake-qt.7.html#automoc

                So if I am guessing correctly cmake is doing something for Qt in generating code and the Qt IDE is doing another part. They don't both follow the same convention....

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

                @Groundbounce said in little bug when creating Q_OBJECT C++ classes:

                They don't both follow the same convention....

                Since QtCreator is an IDE and cmake a build system I don't know what you mean with 'convention'...
                The naming of a function is neither a problem of an IDE nor the build system.

                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
                • G Offline
                  G Offline
                  Groundbounce
                  wrote on last edited by
                  #8

                  The function is auto generated, the function name used in autogenerated files does not match the prototype in the Q_PROPERTY declaration.

                  Christian EhrlicherC 1 Reply Last reply
                  0
                  • G Groundbounce

                    The function is auto generated, the function name used in autogenerated files does not match the prototype in the Q_PROPERTY declaration.

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

                    @Groundbounce said in little bug when creating Q_OBJECT C++ classes:

                    The function is auto generated, the function name used in autogenerated files does not match the prototype in the Q_PROPERTY declaration.

                    Since the generation is done from the header file and Q_PROPERTY they can't differ. As soon as you modify the header, the moc file is re-generated.

                    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
                    • G Offline
                      G Offline
                      Groundbounce
                      wrote on last edited by
                      #10

                      Well, they do! I have simply followed the instructions on Qt academy - for what they are worth..... on first build, it fails. I'm sure there is more that needs doing than what was in the tutorial, something about AUTOMOC maybe?. I suspect that like the incorrect instructions for the QRC system I will spend several hours figuring it out for myself, and like any good programmer, keep that knowledge to myself!

                      1 Reply Last reply
                      0
                      • G Offline
                        G Offline
                        Groundbounce
                        wrote on last edited by
                        #11

                        The issue is that QT Creator does not capitalize the first letter of the variable when it adds a word to the start when using the refractor menu option.

                        The MOC file has it automatically renamed. As the MOC file is constantly regenerated I will need to correct the function definitions and declarations.

                        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