c++ - Is it safe to use *virtual* multiple inheritance if QObject is being derived from DIRECTLY? -


i understand in general, multiple inheritance qobject-derived classes (even virtual multiple inheritance) not supported in qt.

i understand reason (i think) in virtual inheritance case, qt classes not themselves virtually inherit qobject. example, if attempt derive class virtually both qwidget , qthread, placing virtual inheritance in irrelevant place in inheritance chain , still wind 2 qobject instances.

i therefore think safe, , supported in qt, use virtual inheritance qt class being derived qobject itself.

i have:

class top : public qobject {};  class left : public virtual top {};  class right : public virtual top {};  class bottom : public left, public right {}; // safe, , supported qt? 

note instances of bottom have 1 instance of top (and hence 1 instance of qobject), seems rationale avoiding multiple inheritance in qt (even virtual multiple inheritance) not apply here.

the above construct nonetheless results in qt compiler warning class bottom inherits 2 qobject subclasses left , right. not supported!.

am correct? safe ignore qt compiler warning in specific scenario? above construct, involving virtual multiple inheritance directly qobject, safe , supported in qt?

no, multiple inheritance qobject not supported qt in way.

the problem not virtual inheritance, it's qt's meta-object system. each qobject base class has associated qmetaobject manages signals, slots, properties, etc, , each meta-object knows parent qobject e.g. signals exist in parent classes can handled. qt moc not able deal multiple inheritance qobject or of sub-classes.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -