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
QtWS25 Last Chance

Dialog UI and heritage

Scheduled Pinned Locked Moved Solved General and Desktop
ui and heritage
14 Posts 4 Posters 3.8k 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.
  • M Offline
    M Offline
    mrjj
    Lifetime Qt Champion
    wrote on 27 Nov 2015, 09:40 last edited by
    #4

    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?

    C 1 Reply Last reply 27 Nov 2015, 10:24
    0
    • M mrjj
      27 Nov 2015, 09:40

      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?

      C Offline
      C Offline
      cfdev
      wrote on 27 Nov 2015, 10:24 last edited by
      #5

      @mrjj Yes, not in header file

      M 1 Reply Last reply 27 Nov 2015, 10:26
      0
      • C cfdev
        27 Nov 2015, 10:24

        @mrjj Yes, not in header file

        M Offline
        M Offline
        mrjj
        Lifetime Qt Champion
        wrote on 27 Nov 2015, 10:26 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
        • C cfdev
          27 Nov 2015, 09:17

          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 27 Nov 2015, 12:05 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.

          C 1 Reply Last reply 27 Nov 2015, 13:44
          1
          • J Offline
            J Offline
            Jakob
            wrote on 27 Nov 2015, 12:06 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
              27 Nov 2015, 12:05

              @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.

              C Offline
              C Offline
              cfdev
              wrote on 27 Nov 2015, 13:44 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
              • C Offline
                C Offline
                cfdev
                wrote on 1 Dec 2015, 08:29 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 Dec 2015, 20:10
                1
                • C cfdev
                  1 Dec 2015, 08:29

                  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 1 Dec 2015, 20:10 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
                  • C cfdev
                    1 Dec 2015, 08:29

                    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 1 Dec 2015, 20:12 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
                    • C cfdev
                      1 Dec 2015, 08:29

                      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 1 Dec 2015, 20:13 last edited by
                      #13

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

                      1 Reply Last reply
                      0
                      • S Offline
                        S Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on 1 Dec 2015, 21:38 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

                        13/14

                        1 Dec 2015, 20:13

                        • Login

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