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. Dialog UI and heritage
Qt 6.11 is out! See what's new in the release blog

Dialog UI and heritage

Scheduled Pinned Locked Moved Solved General and Desktop
ui and heritage
14 Posts 4 Posters 5.3k Views 2 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.
  • mrjjM mrjj

    the implementation of your function must be in the .cpp file.

    so where you call ui -> dateEdit -> setDate( QDate::currentDate());
    should be in a .cpp file and not .h

    Is it in .cpp?

    cfdevC Offline
    cfdevC Offline
    cfdev
    wrote on last edited by
    #5

    @mrjj Yes, not in header file

    mrjjM 1 Reply Last reply
    0
    • cfdevC cfdev

      @mrjj Yes, not in header file

      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #6

      @cfdev
      ok, so not that error.
      Well, I have not tried to move it to protected.
      I can try it a bit later and see :)

      1 Reply Last reply
      0
      • cfdevC cfdev

        Hi Sorry if this question is too simple :)

        I have an class
        namespace Ui { class DialogInvoiceList; }
        class DialogInvoiceList : public QDialog { ...}

        I want to create an other class from DialogInvoiceList
        class DialogPurchase : public DialogInvoiceList

        Here it's ok, but How to access to ui functions in my DialogPurchase class?
        ui -> dateEdit -> setDate( QDate::currentDate());

        J Offline
        J Offline
        Jakob
        wrote on last edited by
        #7

        @cfdev How did you embed Ui::DialogInvoiceList into your DialogInvoiceList? In your example the ui-class is nowhere!

        Anyways, if you wanted to create a hierarchy of classes that derive from your ui-class, then the logical thing I'd do:

        namespace Ui { class DialogInvoiceList; }
        
        class DialogInvoiceList: protected DialogInvoiceList, public QDialog
        {
            Q_OBJECT
        public:
            explicit DialogInvoiceList(QWidget* parent) 
                : QDialog(parent)
            {
                setupUi(this);
            }
        }
        
        class DialogPurchase : protected DialogInvoiceList
        {
            Q_OBJECT
        public:
            explicit DialogPurchase(QWidget* parent)
                : DialogInvoiceList(parent)
            {}
        }
        

        I haven't tested, but I'm almost certain you can now access anything in the ui class directly, i.e. a member checkbox can be accessed directly in the DialogPurchase class.

        cfdevC 1 Reply Last reply
        1
        • J Offline
          J Offline
          Jakob
          wrote on last edited by
          #8

          @cfdev To be more precize, you'd use the 'Multiple Inheritance' approach described here http://doc.qt.io/qt-5/designer-using-a-ui-file.html#the-multiple-inheritance-approach

          1 Reply Last reply
          1
          • J Jakob

            @cfdev How did you embed Ui::DialogInvoiceList into your DialogInvoiceList? In your example the ui-class is nowhere!

            Anyways, if you wanted to create a hierarchy of classes that derive from your ui-class, then the logical thing I'd do:

            namespace Ui { class DialogInvoiceList; }
            
            class DialogInvoiceList: protected DialogInvoiceList, public QDialog
            {
                Q_OBJECT
            public:
                explicit DialogInvoiceList(QWidget* parent) 
                    : QDialog(parent)
                {
                    setupUi(this);
                }
            }
            
            class DialogPurchase : protected DialogInvoiceList
            {
                Q_OBJECT
            public:
                explicit DialogPurchase(QWidget* parent)
                    : DialogInvoiceList(parent)
                {}
            }
            

            I haven't tested, but I'm almost certain you can now access anything in the ui class directly, i.e. a member checkbox can be accessed directly in the DialogPurchase class.

            cfdevC Offline
            cfdevC Offline
            cfdev
            wrote on last edited by
            #9

            @Jakob If I use this code, I've some error 'inaccessible' :

            D:\code\qt\4.8.7\src\gui\dialogs\qdialog.h:90: error: 'void QDialog::setModal(bool)' is inaccessible void setModal(bool modal);

            D:\code\mcercle-trunk\src\mainwindow.cpp:323: error: 'QDialog' is not an accessible base of 'DialogPurchase'
            ...

            PS: What is the markdown code to use the syntax color ?!

            1 Reply Last reply
            0
            • cfdevC Offline
              cfdevC Offline
              cfdev
              wrote on last edited by
              #10

              It's ok like this:

              namespace Ui { class DialogInvoiceList; }

              class DialogInvoiceList: public QDialog, protected Ui::DialogInvoiceList
              {
              Q_OBJECT
              public:
              explicit DialogInvoiceList(QWidget* parent)
              : QDialog(parent)
              {
              setupUi(this);
              }
              }

              class DialogPurchase : public DialogInvoiceList
              {
              Q_OBJECT
              public:
              explicit DialogPurchase(QWidget* parent)
              : DialogInvoiceList(parent)
              {}
              }

              Many Thanks ;)

              J 3 Replies Last reply
              1
              • cfdevC cfdev

                It's ok like this:

                namespace Ui { class DialogInvoiceList; }

                class DialogInvoiceList: public QDialog, protected Ui::DialogInvoiceList
                {
                Q_OBJECT
                public:
                explicit DialogInvoiceList(QWidget* parent)
                : QDialog(parent)
                {
                setupUi(this);
                }
                }

                class DialogPurchase : public DialogInvoiceList
                {
                Q_OBJECT
                public:
                explicit DialogPurchase(QWidget* parent)
                : DialogInvoiceList(parent)
                {}
                }

                Many Thanks ;)

                J Offline
                J Offline
                Jakob
                wrote on last edited by
                #11

                @cfdev Aaahhh, of course, that actually rings some bells somewhere in the back of my head. I think I read somewhere that if you use multiple inheritance, the QObject-derived class must be the first in the list. This has something to do with the moc compiler I think.

                You get the syntax highlighted using a single backtick for inline highlighting and backtick plus return for a code block.

                1 Reply Last reply
                0
                • cfdevC cfdev

                  It's ok like this:

                  namespace Ui { class DialogInvoiceList; }

                  class DialogInvoiceList: public QDialog, protected Ui::DialogInvoiceList
                  {
                  Q_OBJECT
                  public:
                  explicit DialogInvoiceList(QWidget* parent)
                  : QDialog(parent)
                  {
                  setupUi(this);
                  }
                  }

                  class DialogPurchase : public DialogInvoiceList
                  {
                  Q_OBJECT
                  public:
                  explicit DialogPurchase(QWidget* parent)
                  : DialogInvoiceList(parent)
                  {}
                  }

                  Many Thanks ;)

                  J Offline
                  J Offline
                  Jakob
                  wrote on last edited by
                  #12

                  @cfdev Btw, please remember to mark as 'Solved' using the 'Topic Tools' at the bottom right corner of the topic thread.

                  1 Reply Last reply
                  1
                  • cfdevC cfdev

                    It's ok like this:

                    namespace Ui { class DialogInvoiceList; }

                    class DialogInvoiceList: public QDialog, protected Ui::DialogInvoiceList
                    {
                    Q_OBJECT
                    public:
                    explicit DialogInvoiceList(QWidget* parent)
                    : QDialog(parent)
                    {
                    setupUi(this);
                    }
                    }

                    class DialogPurchase : public DialogInvoiceList
                    {
                    Q_OBJECT
                    public:
                    explicit DialogPurchase(QWidget* parent)
                    : DialogInvoiceList(parent)
                    {}
                    }

                    Many Thanks ;)

                    J Offline
                    J Offline
                    Jakob
                    wrote on last edited by
                    #13

                    @cfdev Damn browser cache, never mind the remark as marking as 'Solved' - you already did .......

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

                      Hi,

                      Just a side note, you have now a "Code" button with </> as an icon to help you write code blocks

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/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