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. Inheritance of a Designer form class problems
QtWS25 Last Chance

Inheritance of a Designer form class problems

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 1.6k Views
  • 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.
  • D Offline
    D Offline
    danifujii
    wrote on last edited by
    #1

    Hi!
    I am needing you help. The thing is I have a Qt Designer Form Class A (.ui, .h and .cpp). I have defined some methods using such ui. Now, I want to create a new class B that can define another methods but use the same .ui and have access to the first methods too.
    I was able to use the same UI by inheriting QWidget in the new class B and declaring in B.h:

        Ui::A * ui; //at .h
    

    And in the constructor doing:

    B::B(QWidget *parent):ui(new Ui::A)
    

    The problem is that I am missing the access to the methods (remember these methods use the UI of A, so the same .ui is needed). I thought inheriting directly from class A would work, but I am having no luck. The error I get is "invalid use of incomplete type 'class A'".
    Is it possible to do this? All I can find on the internet is about using a .ui file. Nothing like this unfortunately.
    Thank you very much.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Why not just inherit from A ?

      i.e.

      #include "a.h"
      
      class B: public A
      {
      public:
          B (QWidget *parent = nullptr);
      
      // rest of your code
      };
      

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      D 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Why not just inherit from A ?

        i.e.

        #include "a.h"
        
        class B: public A
        {
        public:
            B (QWidget *parent = nullptr);
        
        // rest of your code
        };
        
        D Offline
        D Offline
        danifujii
        wrote on last edited by
        #3

        @SGaist Well, I have tried that. Getting the error that is in the last paragraph.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Maybe a silly question but did you include a.h properly ?

          Usually when you get "incomplete type 'class XXX'" it means that you are missing the include of the file that declares 'class XXX'

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          kshegunovK 1 Reply Last reply
          0
          • SGaistS SGaist

            Maybe a silly question but did you include a.h properly ?

            Usually when you get "incomplete type 'class XXX'" it means that you are missing the include of the file that declares 'class XXX'

            kshegunovK Offline
            kshegunovK Offline
            kshegunov
            Moderators
            wrote on last edited by kshegunov
            #5

            @danifujii
            Since Ui::A is a generated class, how exactly are you adding methods to it? Whatsoever you add to the "ui_a.h" file will be overwritten on the next run of the user interface compiler, so maybe elaborate a bit?

            Kind regards.

            Read and abide by the Qt Code of Conduct

            D 1 Reply Last reply
            0
            • kshegunovK kshegunov

              @danifujii
              Since Ui::A is a generated class, how exactly are you adding methods to it? Whatsoever you add to the "ui_a.h" file will be overwritten on the next run of the user interface compiler, so maybe elaborate a bit?

              Kind regards.

              D Offline
              D Offline
              danifujii
              wrote on last edited by
              #6

              @kshegunov Well, I have a full class. The methods are added to A.h. I use the files that the wizard creates when adding a new Qt Designer Form class.

              kshegunovK 1 Reply Last reply
              0
              • D danifujii

                @kshegunov Well, I have a full class. The methods are added to A.h. I use the files that the wizard creates when adding a new Qt Designer Form class.

                kshegunovK Offline
                kshegunovK Offline
                kshegunov
                Moderators
                wrote on last edited by kshegunov
                #7

                @danifujii said:

                I use the files that the wizard creates when adding a new Qt Designer Form class.

                The question is how, since I personally don't derive from the generated form classes, so can we assume you do in your "a.h"?
                That is, do you have something like this in "a.h":

                #include "ui_a.h"
                class A : public QWidget, public Ui::A
                {
                    // Some code
                };
                

                Read and abide by the Qt Code of Conduct

                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