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. QSqlRelationalTableModel with multiple Joins?
Forum Updated to NodeBB v4.3 + New Features

QSqlRelationalTableModel with multiple Joins?

Scheduled Pinned Locked Moved Unsolved General and Desktop
67 Posts 4 Posters 24.9k 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.
  • J JonB
    8 Feb 2018, 16:54

    @devhobby
    I'm a little lost. You wrote:

    Thanks but before doing that, I was wondering if there's a way to change the content of the cell by directly typing into it.

    I thought you were saying when double-click it does not let you edit, nothing happens, or whatever. Now I think you're saying it does let you edit? I don't know if you have a question here?

    D Offline
    D Offline
    devhobby
    wrote on 8 Feb 2018, 16:56 last edited by devhobby 2 Aug 2018, 16:58
    #21

    @JonB said in QSqlRelationalTableModel with multiple Joins?:

    @devhobby
    I'm a little lost. You wrote:

    Thanks but before doing that, I was wondering if there's a way to change the content of the cell by directly typing into it.

    I thought you were saying when double-click it does not let you edit, nothing happens, or whatever. Now I think you're saying it does let you edit? I don't know if you have a question here?

    Yes I asked if there's a way to change the content of the cell by directly typing into it

    Because now, when I double click, nothing happens.

    Once the cell is edited, I'd also like to change its background color... but that's another story

    J 1 Reply Last reply 8 Feb 2018, 17:01
    0
    • D devhobby
      8 Feb 2018, 16:56

      @JonB said in QSqlRelationalTableModel with multiple Joins?:

      @devhobby
      I'm a little lost. You wrote:

      Thanks but before doing that, I was wondering if there's a way to change the content of the cell by directly typing into it.

      I thought you were saying when double-click it does not let you edit, nothing happens, or whatever. Now I think you're saying it does let you edit? I don't know if you have a question here?

      Yes I asked if there's a way to change the content of the cell by directly typing into it

      Because now, when I double click, nothing happens.

      Once the cell is edited, I'd also like to change its background color... but that's another story

      J Offline
      J Offline
      JonB
      wrote on 8 Feb 2018, 17:01 last edited by
      #22

      @devhobby said in QSqlRelationalTableModel with multiple Joins?:

      Once the user changes the text of the cell, the new text is immediately visible and I store it in a QString

      Because now, when I double click, nothing happens.

      Sorry, but if "nothing happens" when you double-click cell to edit, how come you talk about "Once the user changes the text of the cell"? Maybe I'm being dumb, but I just don't get it!

      D 1 Reply Last reply 8 Feb 2018, 17:04
      1
      • J JonB
        8 Feb 2018, 17:01

        @devhobby said in QSqlRelationalTableModel with multiple Joins?:

        Once the user changes the text of the cell, the new text is immediately visible and I store it in a QString

        Because now, when I double click, nothing happens.

        Sorry, but if "nothing happens" when you double-click cell to edit, how come you talk about "Once the user changes the text of the cell"? Maybe I'm being dumb, but I just don't get it!

        D Offline
        D Offline
        devhobby
        wrote on 8 Feb 2018, 17:04 last edited by
        #23

        @JonB said in QSqlRelationalTableModel with multiple Joins?:

        @devhobby said in QSqlRelationalTableModel with multiple Joins?:

        Once the user changes the text of the cell, the new text is immediately visible and I store it in a QString

        Because now, when I double click, nothing happens.

        Sorry, but if "nothing happens" when you double-click cell to edit, how come you talk about "Once the user changes the text of the cell"? Maybe I'm being dumb, but I just don't get it!

        Don't worry! I'm sorry, I'm probably using the wrong tenses to express myself.

        "Once the user changes the text of the cell, the new text is immediately visible and I store it in a QString"

        Is the prediction of what I want to happen... and can't manage to make it happen actually

        J 1 Reply Last reply 8 Feb 2018, 17:07
        1
        • D devhobby
          8 Feb 2018, 17:04

          @JonB said in QSqlRelationalTableModel with multiple Joins?:

          @devhobby said in QSqlRelationalTableModel with multiple Joins?:

          Once the user changes the text of the cell, the new text is immediately visible and I store it in a QString

          Because now, when I double click, nothing happens.

          Sorry, but if "nothing happens" when you double-click cell to edit, how come you talk about "Once the user changes the text of the cell"? Maybe I'm being dumb, but I just don't get it!

          Don't worry! I'm sorry, I'm probably using the wrong tenses to express myself.

          "Once the user changes the text of the cell, the new text is immediately visible and I store it in a QString"

          Is the prediction of what I want to happen... and can't manage to make it happen actually

          J Offline
          J Offline
          JonB
          wrote on 8 Feb 2018, 17:07 last edited by JonB 2 Aug 2018, 17:07
          #24

          @devhobby

          Is the prediction of what I want to happen... and can't manage to make it happen actually

          Ohhhh...! :)

          OK, I would expect you've done the right stuff. I believe that's what our code does. I can only think of what I suggested: that the SELECT makes the model read-only, and editing is not allowed.

          I shall step aside and you need an expert here to guide you further....

          D 1 Reply Last reply 8 Feb 2018, 17:09
          1
          • J JonB
            8 Feb 2018, 17:07

            @devhobby

            Is the prediction of what I want to happen... and can't manage to make it happen actually

            Ohhhh...! :)

            OK, I would expect you've done the right stuff. I believe that's what our code does. I can only think of what I suggested: that the SELECT makes the model read-only, and editing is not allowed.

            I shall step aside and you need an expert here to guide you further....

            D Offline
            D Offline
            devhobby
            wrote on 8 Feb 2018, 17:09 last edited by devhobby 2 Aug 2018, 17:09
            #25

            @JonB said in QSqlRelationalTableModel with multiple Joins?:

            @devhobby

            Is the prediction of what I want to happen... and can't manage to make it happen actually

            Ohhhh...! :)

            OK, I would expect you've done the right stuff. I believe that's what our code does. I can only think of what I suggested: that the SELECT makes the model read-only, and editing is not allowed.

            I shall step aside and you need an expert here to guide you further....

            Yes, the custom query is most likely keeping my Table View read-only.

            I just want to visually edit the cells...

            This is far more complicated than I thought...

            J 1 Reply Last reply 8 Feb 2018, 17:14
            0
            • D devhobby
              8 Feb 2018, 17:09

              @JonB said in QSqlRelationalTableModel with multiple Joins?:

              @devhobby

              Is the prediction of what I want to happen... and can't manage to make it happen actually

              Ohhhh...! :)

              OK, I would expect you've done the right stuff. I believe that's what our code does. I can only think of what I suggested: that the SELECT makes the model read-only, and editing is not allowed.

              I shall step aside and you need an expert here to guide you further....

              Yes, the custom query is most likely keeping my Table View read-only.

              I just want to visually edit the cells...

              This is far more complicated than I thought...

              J Offline
              J Offline
              JonB
              wrote on 8 Feb 2018, 17:14 last edited by JonB 2 Aug 2018, 17:41
              #26

              @devhobby
              http://doc.qt.io/qt-5/qitemdelegate.html#details must be to do with it.

              I could easily be wrong(!), but I thought the idea of the model/view would be that if you edit it would save the value back to the model, not "just give you some string". You can doubtless play with the delegate to do something else...

              P.S.
              Look at http://www.qtcentre.org/threads/38338-Can-t-edit-my-QTableView-cells:

              Check if the item is actually editable: (MyTable->model()->flags(idx) & Qt::ItemIsEditable). If not, make it so.

              https://stackoverflow.com/questions/28186118/how-to-make-qtableview-to-enter-the-editing-mode-only-on-double-click:

              Setting a Qt.ItemIsEnabled flag makes the QTableView items editable. To enter the item's editing mode the user can simply double-click it.

              EDIT: You have to loop over every item in your table view to make it individually editable....

              D 1 Reply Last reply 8 Feb 2018, 17:37
              2
              • J JonB
                8 Feb 2018, 17:14

                @devhobby
                http://doc.qt.io/qt-5/qitemdelegate.html#details must be to do with it.

                I could easily be wrong(!), but I thought the idea of the model/view would be that if you edit it would save the value back to the model, not "just give you some string". You can doubtless play with the delegate to do something else...

                P.S.
                Look at http://www.qtcentre.org/threads/38338-Can-t-edit-my-QTableView-cells:

                Check if the item is actually editable: (MyTable->model()->flags(idx) & Qt::ItemIsEditable). If not, make it so.

                https://stackoverflow.com/questions/28186118/how-to-make-qtableview-to-enter-the-editing-mode-only-on-double-click:

                Setting a Qt.ItemIsEnabled flag makes the QTableView items editable. To enter the item's editing mode the user can simply double-click it.

                EDIT: You have to loop over every item in your table view to make it individually editable....

                D Offline
                D Offline
                devhobby
                wrote on 8 Feb 2018, 17:37 last edited by
                #27

                @JonB said in QSqlRelationalTableModel with multiple Joins?:

                @devhobby
                http://doc.qt.io/qt-5/qitemdelegate.html#details must be to do with it.

                I could easily be wrong(!), but I thought the idea of the model/view would be that if you edit it would save the value back to the model, not "just give you some string". You can doubtless play with the delegate to do something else...

                P.S.
                Look at http://www.qtcentre.org/threads/38338-Can-t-edit-my-QTableView-cells:

                Check if the item is actually editable: (MyTable->model()->flags(idx) & Qt::ItemIsEditable). If not, make it so.

                https://stackoverflow.com/questions/28186118/how-to-make-qtableview-to-enter-the-editing-mode-only-on-double-click:

                Setting a Qt.ItemIsEnabled flag makes the QTableView items editable. To enter the item's editing mode the user can simply double-click it.

                I'd like to change Table View's flag to Qt::ItemIsEditable... but can't find a way to do it

                There's no setFlags() method here...

                J 1 Reply Last reply 8 Feb 2018, 17:42
                0
                • D devhobby
                  8 Feb 2018, 17:37

                  @JonB said in QSqlRelationalTableModel with multiple Joins?:

                  @devhobby
                  http://doc.qt.io/qt-5/qitemdelegate.html#details must be to do with it.

                  I could easily be wrong(!), but I thought the idea of the model/view would be that if you edit it would save the value back to the model, not "just give you some string". You can doubtless play with the delegate to do something else...

                  P.S.
                  Look at http://www.qtcentre.org/threads/38338-Can-t-edit-my-QTableView-cells:

                  Check if the item is actually editable: (MyTable->model()->flags(idx) & Qt::ItemIsEditable). If not, make it so.

                  https://stackoverflow.com/questions/28186118/how-to-make-qtableview-to-enter-the-editing-mode-only-on-double-click:

                  Setting a Qt.ItemIsEnabled flag makes the QTableView items editable. To enter the item's editing mode the user can simply double-click it.

                  I'd like to change Table View's flag to Qt::ItemIsEditable... but can't find a way to do it

                  There's no setFlags() method here...

                  J Offline
                  J Offline
                  JonB
                  wrote on 8 Feb 2018, 17:42 last edited by JonB 2 Aug 2018, 17:49
                  #28

                  @devhobby
                  You have to loop over every item in your table view to make it individually editable (if you're not creating the items yourself, or unless someone suggests a way to cause that to happen as it binds to your model, e.g. https://stackoverflow.com/a/28226056/489865)....

                  D 1 Reply Last reply 8 Feb 2018, 17:47
                  1
                  • J JonB
                    8 Feb 2018, 17:42

                    @devhobby
                    You have to loop over every item in your table view to make it individually editable (if you're not creating the items yourself, or unless someone suggests a way to cause that to happen as it binds to your model, e.g. https://stackoverflow.com/a/28226056/489865)....

                    D Offline
                    D Offline
                    devhobby
                    wrote on 8 Feb 2018, 17:47 last edited by
                    #29

                    @JonB said in QSqlRelationalTableModel with multiple Joins?:

                    @devhobby
                    You have to loop over every item in your table view to make it individually editable (if you're not creating the items yourself, or unless someone suggests a way to cause that to happen as it binds to your model)....

                    Suppose I'm inside a for loop where index is a QModelIndex

                    ui->tableView->model()->data(index). ???
                    

                    There's no setFlags here still

                    J 1 Reply Last reply 8 Feb 2018, 18:30
                    0
                    • D devhobby
                      8 Feb 2018, 17:47

                      @JonB said in QSqlRelationalTableModel with multiple Joins?:

                      @devhobby
                      You have to loop over every item in your table view to make it individually editable (if you're not creating the items yourself, or unless someone suggests a way to cause that to happen as it binds to your model)....

                      Suppose I'm inside a for loop where index is a QModelIndex

                      ui->tableView->model()->data(index). ???
                      

                      There's no setFlags here still

                      J Offline
                      J Offline
                      JonB
                      wrote on 8 Feb 2018, 18:30 last edited by JonB 2 Aug 2018, 18:51
                      #30

                      @devhobby

                      I think we use QTableWidget, not just QTableView.

                      http://www.qtcentre.org/threads/46245-QTableWidgetItem-setflags-strange-behavior?p=209282#post209282 shows you accessing QTableWidgetItem. http://doc.qt.io/qt-5/qtablewidget.html#item

                      http://doc.qt.io/qt-5/qtablewidget.html#details:

                      The QTableWidget class provides an item-based table view with a default model.
                      Table widgets provide standard table display facilities for applications. The items in a QTableWidget are provided by QTableWidgetItem.
                      If you want a table that uses your own data model you should use QTableView rather than this class.

                      But for QTableView I previously gave you http://www.qtcentre.org/threads/38338-Can-t-edit-my-QTableView-cells?p=176235#post176235:

                      Qt::ItemFlags MyTableModel::flags (const QModelIndex &index) const
                      {
                         return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
                      }
                      

                      http://doc.qt.io/qt-5/qabstractitemmodel.html#flags, http://doc.qt.io/qt-5/qabstracttablemodel.html#flags works off the model, so presumably your ui->tableView->model()->flags(index).

                      Ah ha!! Here's what we wanted to know:
                      http://doc.qt.io/qt-5/qsqlquerymodel.html#details

                      The model is read-only by default. To make it read-write, you must subclass it and reimplement setData() and flags(). Another option is to use QSqlTableModel, which provides a read-write model based on a single database table.

                      D 1 Reply Last reply 8 Feb 2018, 18:46
                      1
                      • J JonB
                        8 Feb 2018, 18:30

                        @devhobby

                        I think we use QTableWidget, not just QTableView.

                        http://www.qtcentre.org/threads/46245-QTableWidgetItem-setflags-strange-behavior?p=209282#post209282 shows you accessing QTableWidgetItem. http://doc.qt.io/qt-5/qtablewidget.html#item

                        http://doc.qt.io/qt-5/qtablewidget.html#details:

                        The QTableWidget class provides an item-based table view with a default model.
                        Table widgets provide standard table display facilities for applications. The items in a QTableWidget are provided by QTableWidgetItem.
                        If you want a table that uses your own data model you should use QTableView rather than this class.

                        But for QTableView I previously gave you http://www.qtcentre.org/threads/38338-Can-t-edit-my-QTableView-cells?p=176235#post176235:

                        Qt::ItemFlags MyTableModel::flags (const QModelIndex &index) const
                        {
                           return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
                        }
                        

                        http://doc.qt.io/qt-5/qabstractitemmodel.html#flags, http://doc.qt.io/qt-5/qabstracttablemodel.html#flags works off the model, so presumably your ui->tableView->model()->flags(index).

                        Ah ha!! Here's what we wanted to know:
                        http://doc.qt.io/qt-5/qsqlquerymodel.html#details

                        The model is read-only by default. To make it read-write, you must subclass it and reimplement setData() and flags(). Another option is to use QSqlTableModel, which provides a read-write model based on a single database table.

                        D Offline
                        D Offline
                        devhobby
                        wrote on 8 Feb 2018, 18:46 last edited by devhobby 2 Aug 2018, 18:48
                        #31

                        @JonB said in QSqlRelationalTableModel with multiple Joins?:

                        @devhobby

                        I think we use QTableWidget, not just QTableView.

                        http://www.qtcentre.org/threads/46245-QTableWidgetItem-setflags-strange-behavior?p=209282#post209282 shows you accessing QTableWidgetItem. http://doc.qt.io/qt-5/qtablewidget.html#item

                        http://doc.qt.io/qt-5/qtablewidget.html#details:

                        The QTableWidget class provides an item-based table view with a default model.
                        Table widgets provide standard table display facilities for applications. The items in a QTableWidget are provided by QTableWidgetItem.
                        If you want a table that uses your own data model you should use QTableView rather than this class.

                        But for QTableView I previously gave you http://www.qtcentre.org/threads/38338-Can-t-edit-my-QTableView-cells?p=176235#post176235:

                        Qt::ItemFlags MyTableModel::flags (const QModelIndex &index) const
                        {
                           return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
                        }
                        

                        At this point I don't even know which of the 2 (table view/table widget) is the most appropriate for my situation.

                        The last post you linked says to reimplement the method flags() but I don't understand: after inheriting from AbstractItemModel (and reimplementing the method), what am I supposed to do?

                        J 2 Replies Last reply 8 Feb 2018, 18:51
                        0
                        • D devhobby
                          8 Feb 2018, 18:46

                          @JonB said in QSqlRelationalTableModel with multiple Joins?:

                          @devhobby

                          I think we use QTableWidget, not just QTableView.

                          http://www.qtcentre.org/threads/46245-QTableWidgetItem-setflags-strange-behavior?p=209282#post209282 shows you accessing QTableWidgetItem. http://doc.qt.io/qt-5/qtablewidget.html#item

                          http://doc.qt.io/qt-5/qtablewidget.html#details:

                          The QTableWidget class provides an item-based table view with a default model.
                          Table widgets provide standard table display facilities for applications. The items in a QTableWidget are provided by QTableWidgetItem.
                          If you want a table that uses your own data model you should use QTableView rather than this class.

                          But for QTableView I previously gave you http://www.qtcentre.org/threads/38338-Can-t-edit-my-QTableView-cells?p=176235#post176235:

                          Qt::ItemFlags MyTableModel::flags (const QModelIndex &index) const
                          {
                             return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
                          }
                          

                          At this point I don't even know which of the 2 (table view/table widget) is the most appropriate for my situation.

                          The last post you linked says to reimplement the method flags() but I don't understand: after inheriting from AbstractItemModel (and reimplementing the method), what am I supposed to do?

                          J Offline
                          J Offline
                          JonB
                          wrote on 8 Feb 2018, 18:51 last edited by JonB 2 Aug 2018, 19:03
                          #32

                          @devhobby
                          Look at the last bit I just added to my post above.

                          To make it [QSqlQueryModel] read-write, you must subclass it and reimplement setData() and flags().

                          (And BTW when you've done that there won't be any "iterating over items and setting the editable flag", your items will be editable through your reimplementation of QSqlQueryModel::flags().)

                          You understand how to "subclass", and how to "reimplement [override] virtual methods", don't you?

                          D 1 Reply Last reply 8 Feb 2018, 19:25
                          1
                          • D devhobby
                            8 Feb 2018, 18:46

                            @JonB said in QSqlRelationalTableModel with multiple Joins?:

                            @devhobby

                            I think we use QTableWidget, not just QTableView.

                            http://www.qtcentre.org/threads/46245-QTableWidgetItem-setflags-strange-behavior?p=209282#post209282 shows you accessing QTableWidgetItem. http://doc.qt.io/qt-5/qtablewidget.html#item

                            http://doc.qt.io/qt-5/qtablewidget.html#details:

                            The QTableWidget class provides an item-based table view with a default model.
                            Table widgets provide standard table display facilities for applications. The items in a QTableWidget are provided by QTableWidgetItem.
                            If you want a table that uses your own data model you should use QTableView rather than this class.

                            But for QTableView I previously gave you http://www.qtcentre.org/threads/38338-Can-t-edit-my-QTableView-cells?p=176235#post176235:

                            Qt::ItemFlags MyTableModel::flags (const QModelIndex &index) const
                            {
                               return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
                            }
                            

                            At this point I don't even know which of the 2 (table view/table widget) is the most appropriate for my situation.

                            The last post you linked says to reimplement the method flags() but I don't understand: after inheriting from AbstractItemModel (and reimplementing the method), what am I supposed to do?

                            J Offline
                            J Offline
                            JonB
                            wrote on 8 Feb 2018, 19:20 last edited by JonB 2 Aug 2018, 19:26
                            #33

                            @devhobby
                            I'm going back to your very original post and thinking about what you're actually trying to achieve anyway. The code we're talking about is all well & good, if you want to proceed, but I'm wondering about your expectations of the interface.

                            In your pic of Employee table only, you have 1 row per employee. When you say:

                            I want to join the Employee table with EmployeePosition and EmployeeResource so that I can also see, for each employee, their positions and resources (if they have any!)

                            what are you expecting the table interface to be for the multiple positions & resources you say employees have?

                            It's all very well to say:

                            What I need, hence, is a full outer join
                            The query above gives me everything I want to know and see on the Table View

                            [I'm trusting that your code implements FULL OUTER JOIN] but left to its own devices this will mean you have many rows per employee, for each position/resource variant. Is that what you intend??

                            One thing to understand: when you're using QSqlRelationalTableModel so that you can "look up" position/resource names, the combobox you'll get will only ever allow single selection, if you're imagining that it might provide multiple selection it won't.

                            1 Reply Last reply
                            1
                            • J JonB
                              8 Feb 2018, 18:51

                              @devhobby
                              Look at the last bit I just added to my post above.

                              To make it [QSqlQueryModel] read-write, you must subclass it and reimplement setData() and flags().

                              (And BTW when you've done that there won't be any "iterating over items and setting the editable flag", your items will be editable through your reimplementation of QSqlQueryModel::flags().)

                              You understand how to "subclass", and how to "reimplement [override] virtual methods", don't you?

                              D Offline
                              D Offline
                              devhobby
                              wrote on 8 Feb 2018, 19:25 last edited by devhobby 2 Aug 2018, 19:39
                              #34

                              @JonB said in QSqlRelationalTableModel with multiple Joins?:

                              @devhobby
                              Look at the last bit I just added to my post above.

                              To make it [QSqlQueryModel] read-write, you must subclass it and reimplement setData() and flags().

                              (And BTW when you've done that there won't be any "iterating over items and setting the editable flag", your items will be editable through your reimplementation of QSqlQueryModel::flags().)

                              You understand how to "subclass", and how to "reimplement [override] virtual methods", don't you?

                              I have my CustomModel class now deriving from QSqlQueryModel

                              #ifndef CUSTOMMODEL_H
                              #define CUSTOMMODEL_H
                              #include <QSqlQueryModel>
                              
                              class CustomModel : public QSqlQueryModel
                              {
                                  Q_OBJECT
                                  
                              public:
                                  bool setData(const QModelIndex &index, const QVariant &value, int role) override;
                                  Qt::ItemFlags flags(const QModelIndex &index) const override;
                              };
                              
                              #endif
                              

                              The problem is...

                              0_1518117868934_4f8b1d3f-c5cf-43c9-b900-be0b15d1ac81-image.png

                              The linker somehow can't match the signatures... weird.

                              I checked this link for example [ https://code.woboq.org/qt5/qtbase/src/corelib/itemmodels/qabstractitemmodel.h.html ]

                              and both setData() and flags() are the same way I overloaded them...

                              J 1 Reply Last reply 8 Feb 2018, 19:29
                              0
                              • D devhobby
                                8 Feb 2018, 19:25

                                @JonB said in QSqlRelationalTableModel with multiple Joins?:

                                @devhobby
                                Look at the last bit I just added to my post above.

                                To make it [QSqlQueryModel] read-write, you must subclass it and reimplement setData() and flags().

                                (And BTW when you've done that there won't be any "iterating over items and setting the editable flag", your items will be editable through your reimplementation of QSqlQueryModel::flags().)

                                You understand how to "subclass", and how to "reimplement [override] virtual methods", don't you?

                                I have my CustomModel class now deriving from QSqlQueryModel

                                #ifndef CUSTOMMODEL_H
                                #define CUSTOMMODEL_H
                                #include <QSqlQueryModel>
                                
                                class CustomModel : public QSqlQueryModel
                                {
                                    Q_OBJECT
                                    
                                public:
                                    bool setData(const QModelIndex &index, const QVariant &value, int role) override;
                                    Qt::ItemFlags flags(const QModelIndex &index) const override;
                                };
                                
                                #endif
                                

                                The problem is...

                                0_1518117868934_4f8b1d3f-c5cf-43c9-b900-be0b15d1ac81-image.png

                                The linker somehow can't match the signatures... weird.

                                I checked this link for example [ https://code.woboq.org/qt5/qtbase/src/corelib/itemmodels/qabstractitemmodel.h.html ]

                                and both setData() and flags() are the same way I overloaded them...

                                J Offline
                                J Offline
                                JonB
                                wrote on 8 Feb 2018, 19:29 last edited by JonB 2 Aug 2018, 19:51
                                #35

                                @devhobby
                                Now you're talking C++ esotericism, and I'm a Python Qt guy anyway. This one is your problem! :) Sometimes signatures don't match if you don't get your consts just right? What about the Q_INVOKABLE?

                                https://stackoverflow.com/questions/33781346/how-to-write-setdata-in-qsqlquerymodelqabstractitemmodel is an example of what claims to work? (Oohh, it uses Q_DECL_OVERRIDE for your override?)

                                D 1 Reply Last reply 8 Feb 2018, 19:53
                                1
                                • J JonB
                                  8 Feb 2018, 19:29

                                  @devhobby
                                  Now you're talking C++ esotericism, and I'm a Python Qt guy anyway. This one is your problem! :) Sometimes signatures don't match if you don't get your consts just right? What about the Q_INVOKABLE?

                                  https://stackoverflow.com/questions/33781346/how-to-write-setdata-in-qsqlquerymodelqabstractitemmodel is an example of what claims to work? (Oohh, it uses Q_DECL_OVERRIDE for your override?)

                                  D Offline
                                  D Offline
                                  devhobby
                                  wrote on 8 Feb 2018, 19:53 last edited by devhobby 2 Aug 2018, 20:01
                                  #36

                                  @JonB said in QSqlRelationalTableModel with multiple Joins?:

                                  @devhobby
                                  Oohh, it uses Q_DECL_OVERRIDE for your override?

                                  Yes, it is ALSO that.

                                  Something strange is going on here...

                                  I'll try tagging someone @SGaist @VRonin

                                  --- HEADER FILE ---

                                  #ifndef MYMODEL_H
                                  #define MYMODEL_H
                                  
                                  #include <QObject>
                                  #include <QSqlQueryModel>
                                  
                                  class MyModel : public QSqlQueryModel
                                  {
                                      Q_OBJECT
                                  
                                  public:
                                      MyModel(QObject *parent = 0);
                                  
                                      Qt::ItemFlags flags(const QModelIndex &index) const override;
                                      bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
                                  };
                                  
                                  #endif // MYMODEL_H
                                  

                                  --- CPP FILE ---

                                  #include "mymodel.h"
                                  
                                  MyModel::MyModel(QObject *parent) : QSqlQueryModel(parent)
                                  {
                                  }
                                  
                                  Qt::ItemFlags MyModel::flags(const QModelIndex &index) const
                                  {
                                  
                                  }
                                  
                                  bool MyModel::setData(const QModelIndex &index, const QVariant &value, int role)
                                  {
                                  
                                  }
                                  

                                  0_1518119620573_1720abc4-b3c2-4451-9dda-e5b727282cf3-image.png

                                  1 Reply Last reply
                                  0
                                  • SGaistS Offline
                                    SGaistS Offline
                                    SGaist
                                    Lifetime Qt Champion
                                    wrote on 8 Feb 2018, 19:57 last edited by
                                    #37

                                    Your CPP file contains an error, the default value should be in the declaration of the function.

                                    If you are using Qt >= 5.7, you can simply use the override keyword as C++11 support is mandatory since that version. Q_DECL_OVERRIDE was used to allow compatibly with non-C++11 enabled compilers.

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

                                    J D 2 Replies Last reply 8 Feb 2018, 20:00
                                    2
                                    • SGaistS SGaist
                                      8 Feb 2018, 19:57

                                      Your CPP file contains an error, the default value should be in the declaration of the function.

                                      If you are using Qt >= 5.7, you can simply use the override keyword as C++11 support is mandatory since that version. Q_DECL_OVERRIDE was used to allow compatibly with non-C++11 enabled compilers.

                                      J Offline
                                      J Offline
                                      JonB
                                      wrote on 8 Feb 2018, 20:00 last edited by
                                      #38

                                      @SGaist You're a hero ;-) It takes you like 1 minute to spot it & reply!

                                      1 Reply Last reply
                                      1
                                      • SGaistS SGaist
                                        8 Feb 2018, 19:57

                                        Your CPP file contains an error, the default value should be in the declaration of the function.

                                        If you are using Qt >= 5.7, you can simply use the override keyword as C++11 support is mandatory since that version. Q_DECL_OVERRIDE was used to allow compatibly with non-C++11 enabled compilers.

                                        D Offline
                                        D Offline
                                        devhobby
                                        wrote on 8 Feb 2018, 20:01 last edited by devhobby 2 Aug 2018, 20:01
                                        #39

                                        @SGaist said in QSqlRelationalTableModel with multiple Joins?:

                                        Your CPP file contains an error, the default value should be in the declaration of the function.

                                        If you are using Qt >= 5.7, you can simply use the override keyword as C++11 support is mandatory since that version. Q_DECL_OVERRIDE was used to allow compatibly with non-C++11 enabled compilers.

                                        I hoped it was just that...

                                        0_1518120023429_f174cbae-ee6a-42fa-b713-287d8d891eff-image.png

                                        I moved the default value in the header file, same issue

                                        [ I will update the code posted above so that I don't repost it everytime ]

                                        1 Reply Last reply
                                        0
                                        • SGaistS Offline
                                          SGaistS Offline
                                          SGaist
                                          Lifetime Qt Champion
                                          wrote on 8 Feb 2018, 20:22 last edited by
                                          #40

                                          Did you try re-running qmake before building ?

                                          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 8 Feb 2018, 20:55
                                          2

                                          21/67

                                          8 Feb 2018, 16:56

                                          • Login

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