Both QPushButton & QLineEdit are derived from QWidget. But I'm unable to inherit both on to a single class.
When I replicate the same kinda things using generic C++, it works. I'm unable to understand why this doesn't work the same way for Qt classes ?

Qt Code:
  1. // A - Base class
  2. // P, Q - Derived classes from A
  3. // Z - Derived from P, Q
  4. // Works fine with this order.
  5.  
  6. #include <iostream>
  7.  
  8. using namespace std;
  9.  
  10. class A
  11. {
  12. public:
  13. A() { cout << "A::Ctor\n"; }
  14. ~A() { cout << "A::Dtor\n"; }
  15. };
  16.  
  17. class P : public A
  18. {
  19. public:
  20. P() { cout << "P::Ctor\n"; }
  21. ~P() { cout << "P::Dtor\n"; }
  22. };
  23.  
  24. class Q : public A
  25. {
  26. public:
  27. Q() { cout << "Q::Ctor\n"; }
  28. ~Q() { cout << "Q::Dtor\n"; }
  29. };
  30.  
  31. class Z : public P, public Q
  32. {
  33. public:
  34. Z() { cout << "Z::Ctor\n"; }
  35. ~Z() { cout << "Z::Dtor\n"; }
  36. };
  37.  
  38. int main(int argc, char *argv[])
  39. {
  40. Z obj;
  41. return 0;
  42. }
To copy to clipboard, switch view to plain text mode 

But the same kinda inheritance isn't working for Qt classes
Qt Code:
  1. #include <QApplication>
  2. #include <QPushButton>
  3. #include <QLineEdit>
  4. #include <QDebug>
  5.  
  6. class SomeWidget : public QPushButton, public QLineEdit // Both derived from QWidget, which is derived from QObject
  7. {
  8. Q_OBJECT
  9. public:
  10. SomeWidget() { qDebug() << "SomeWidget::Ctor"; }
  11. ~SomeWidget() { qDebug() << "SomeWidget::Dtor"; }
  12. };
  13.  
  14. int main(int argc, char *argv[])
  15. {
  16. QApplication a(argc, argv);
  17.  
  18. SomeWidget wid;
  19. wid.show();
  20.  
  21. return a.exec();
  22. }
  23.  
  24. #include "main.moc"
To copy to clipboard, switch view to plain text mode 

Issues I got when I compiled this
Qt Code:
  1. Warning: Class SomeWidget inherits from two QObject subclasses QPushButton and QLineEdit. This is not supported!
  2. Debug/main.moc:-1: In member function 'virtual const QMetaObject* SomeWidget::metaObject() const':
  3. error: 'QObject' is an ambiguous base of 'SomeWidget'
  4. error: 'QObject' is an ambiguous base of 'SomeWidget'
To copy to clipboard, switch view to plain text mode