little bug when creating Q_OBJECT C++ classes
-
@Groundbounce Better to show some code about how Property is applied.
-
C Christian Ehrlicher moved this topic from General and Desktop
-
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.
-
I remember having some similar issues in previous QtCreator versions.
Are you up to date with your QtCreator? what version are you using? -
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.
-
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....
-
@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. -
The function is auto generated, the function name used in autogenerated files does not match the prototype in the Q_PROPERTY declaration.
-
@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.
-
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!
-
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.