[SOLVED] [Class Inheritance] Need tips on creating a hierarchic class structure
Hi Qt Devs!
I know this is a really vague question, but this could become a major problem if I don’t ask this.
For my interface, I want to subclass QWidget to create specialized widgets. I want a widget for each item that I have in my DB (it sounds like a lot, but for my situation, I think this is the best solution). My items are organized in a tree-like structure, each category having similar properties.
So, I want to create an abstract class that contains very generic virtual member functions that apply to all tests. In turn, I want to have abstract, but further specialized, classes for all nodes in tree structure, down to the very bottom of the tree, where I want to have actual widgets that I can create instances of.
However, when I tried to do that with one class,
- #ifndef CQP_H
- #define CQP_H
- #include <QWidget>
- #include "testroot.h"
- class CQp : public testroot
- {
- Q_OBJECT
- public:
- signals:
- public slots:
- };
- #endif // CQP_H
and when I try to compile, it complains that ‘QWidget’ is not a direct base of CQp. True. But I if make it a parent class to CQp explicitly, it complains that class CQp inherits QWidget from two places. Is there a way around that?
I guess I could make my non-abstract classes inherit QWidget separately, but that seems like ad-hoc solution. Am I missing something?
Anyhow, sorry for the vague question and long post, and thanks in advance for your time and dedication!
11 replies
and when I try to compile, it complains that ‘QWidget’ is not a direct base of CQp. True. But I if make it a parent class to CQp explicitly, it complains that class CQp inherits QWidget from two places. Is there a way around that?
What the compiler is telling you is that from a constructor you can call only direct base constructors.
That is, if you have an inheritance chain like this
- A --> B --> C
(C inherits from B, B from A) then from C::C() you can call B::B(), but not A::A(), because it’s not a direct base for C.
The offending line is obviously the call to the QWidget ctor here, since “testcase” is a direct base for CQp, and QWidget is a non-direct base:
You must log in to post a reply. Not a member yet? Register here!



