Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Direct base ‘QObject’ inaccessible in ‘myClass’ due to ambiguity

Direct base ‘QObject’ inaccessible in ‘myClass’ due to ambiguity

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 20.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    aekam
    wrote on last edited by
    #1

    @// -- header file -------------------------------------------------
    #ifndef MYCLASS_H
    #define MYCLASS_H

    #include <QObject>
    #include <QThread>

    class myClass : public QObject, public QThread
    {
    Q_OBJECT
    public:
    myClass(QObject *parent = 0);
    };

    #endif // MYCLASS_H

    // -- source file ------------------------------------------------
    #include "myclass.h"

    myClass::myClass(QObject *parent) :
    QObject(parent)
    {
    }
    @

    // -- compiler output -----------------------------------------
    myclass.h:9: warning: direct base ‘QObject’ inaccessible in ‘myClass’ due to ambiguity
    myclass.cpp: undefined reference to `vtable for myClass'
    error: collect2: ld returned 1 exit status

    can anyone tell why it fails to compile.???
    and the solution.

    If you take care of inches, you won't have to worry about miles... :)

    1 Reply Last reply
    0
    • A Offline
      A Offline
      aekam
      wrote on last edited by
      #2

      is it because QThread already inherits QObject class, hence when i derive my class from QObject and QThread, compiler gets confuse to select right constructor for QObject...

      If you take care of inches, you won't have to worry about miles... :)

      1 Reply Last reply
      0
      • L Offline
        L Offline
        luisvaldes88
        wrote on last edited by
        #3

        Hello.

        You can not inherit from two QObjects.

        Well, you should read "this":http://developer.qt.nokia.com/doc/qt-4.8/object.html
        and then "this":http://developer.qt.nokia.com/doc/qt-4.8/metaobjects.html#meta-object-system

        I asked myself the same questions once.
        Object Model and The Meta-Object System are the answers

        best regards

        Muchos quieren, pocos pueden, algunos consiguen.

        1 Reply Last reply
        0
        • L Offline
          L Offline
          luisvaldes88
          wrote on last edited by
          #4

          [quote author="aekam" date="1328613590"]is it because QThread already inherits QObject class, hence when i derive my class from QObject and QThread, compiler gets confuse to select right constructor for QObject...[/quote]

          "Using the Meta-Object Compiler (moc)":http://developer.qt.nokia.com/doc/qt-4.8/moc.html#moc
          ...
          Multiple Inheritance Requires QObject to Be First
          If you are using multiple inheritance, moc assumes that the first inherited class is a subclass of QObject. Also, be sure that only the first inherited class is a QObject.
          @
          // correct
          class SomeClass : public QObject, public OtherClass
          {
          ...
          };
          @

          Virtual inheritance with QObject is not supported.

          Muchos quieren, pocos pueden, algunos consiguen.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            miroslav
            wrote on last edited by
            #5

            Inheriting QObject is not necessary, QThread already is one and provides all it's functionality. Simply change it to

            @
            class myClass : public QThread
            {
            Q_OBJECT
            public:

            ...
            @

            [EDIT: code formatting, Volker]

            Mirko Boehm | mirko@kde.org | KDE e.V.
            FSFE Fellow
            Qt Certified Specialist

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved