Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Inheritance in Qt
Qt 6.12 LTS is out! See what's new in the release blog

Inheritance in Qt

Scheduled Pinned Locked Moved C++ Gurus
3 Posts 3 Posters 1.8k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Hi devs!

    This is what I'm trying to do: the class A inherits from B. This the code:

    @// class B.h

    public:
    explicit B();

    // class B.cpp

    B::B() {...}

    //class A.h

    class A : public B
    {
    Q_OBJECT
    public:
    explicit A(QObject *parent = 0);

    //class A.cpp

    A::A(QObject *parent) : B(parent)@

    This doesn't work. Please help me!

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Since B is not a QObject, and does not have a constructor that accepts QObject argument (see the last line of your code snippet), it will not work. You can just skip the B(parent) call and it should be ok.

      (Z(:^

      1 Reply Last reply
      0
      • JKSHJ Offline
        JKSHJ Offline
        JKSH
        Moderators
        wrote on last edited by
        #3

        Also, don't use the Q_OBJECT macro if your class doesn't inherit QObject.

        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

        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
        • Unsolved