PDA

View Full Version : Qt Creator new class wizard vs. class inheritance



googie
4th March 2013, 16:07
Hi,

When I'm adding new class to project in QtCreator I have an option to define its super class. Problem is that the list of classes to inherit from is limited to few Qt classes, like this:
8785

I would like to have all classes available in workspace to be there, so when I create the class it already has virtual methods and proper constructors defined by default etc.

Is this possible? I have QtCreator 5.0.1 under Linux.

wysota
4th March 2013, 16:18
When I'm adding new class to project in QtCreator I have an option to define its super class. Problem is that the list of classes to inherit from is limited to few Qt classes, like this:
8785

I would like to have all classes available in workspace to be there, so when I create the class it already has virtual methods and proper constructors defined by default etc.

Just type in the class name in appropriate box. The combobox is only to choose the "type" of interitance which boils down to whether the generated constructor should accept a QWidget parent, a QObject parent or no parent at all.

Considering you're using an old version of Creator, I'd suggest to upgrade it to something less dinosaur age. And please post in the proper forum next time.

googie
4th March 2013, 17:00
I misinformed you. I'm using QtCreator which comes with Qt 5.0.1, the actual version of QtCreator is 2.6.2. I think it's not that old, isn't it? :)

Back to the main subject - yes, I'm aware I can type any class there, but the problem is that class created with the wizard doesn't #include my super class. It does add it to inheritance chain in class definition, but the #include is missing. Also none of pure virtual methods from superclass are generated in new class, no superclass-specific constructors, etc....

When I do it for QObject it works like expected: the copying constructor for QObject is defined, the #include for QObject is added.
Why doesn't it work for other classes?

wysota
4th March 2013, 17:07
It does add it to inheritance chain in class definition, but the #include is missing.
So add the include.

Also none of pure virtual methods from superclass are generated in new class, no superclass-specific constructors, etc....
I don't see why pure virtual methods would need to be generated. A subclass of a pure virtual class can still have some of the pure virtual methods unimplemented.


Why doesn't it work for other classes?
Because QObject is a well known Qt class with a well defined interface. In case of your own class you can have superclass "A" defined in "sometotallyarbitraryfilename.h". If you feel something is missing in QtCreator, you can implement your own plugin for it or just fix the existing code.

googie
4th March 2013, 18:36
So add the includeReally...? The point of using sophisticated IDE is to have it do stuff for you. Sure developer can do manually everything, but IDE's purpose is to assist, automate and simplify.

I guess that's just not implemented - yet.

wysota
4th March 2013, 18:52
If I remember correctly it was implemented in the old Creator versions but was then removed for some reason. Maybe the team was receiving bug reports such as "Why does Creator include myclass.h instead of {MyClass.h,Myclass.h,myverysophisticatedclass.h}?"