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. QTableView commit data in code
Forum Updated to NodeBB v4.3 + New Features

QTableView commit data in code

Scheduled Pinned Locked Moved General and Desktop
14 Posts 2 Posters 5.7k 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.
  • H Offline
    H Offline
    hsfougaris
    wrote on last edited by
    #1

    I have a model based QTableView (using a QSqlTableModel) that has a manualsubmit policy.
    No custom delegates or proxy models are used, just plain text editors are shown.
    In code, the user clicks a button to save the data.
    The problem is that if the user was typing something and didn't focus out of the current text, the tableview is not posting/submitting data (which is probably a good idea in general, but not what I need).
    Can I somehow force the table view to post whatever is being edited, so I can then safely call submitAll on my model?

    If you can't say what you mean, you'll never be able to mean what you say.

    1 Reply Last reply
    0
    • H Offline
      H Offline
      hsfougaris
      wrote on last edited by
      #2

      Can someone please confirm that this is a "feature" of the QTableView (not being able to programmatically post what the user is editing), and I'm not missing something very obvious here?

      If you can't say what you mean, you'll never be able to mean what you say.

      1 Reply Last reply
      0
      • G Offline
        G Offline
        goetz
        wrote on last edited by
        #3

        Have look at "this reply":http://developer.qt.nokia.com/forums/viewreply/27159/ in another thread. We once ran into the same problem and solved it that way.

        http://www.catb.org/~esr/faqs/smart-questions.html

        1 Reply Last reply
        0
        • H Offline
          H Offline
          hsfougaris
          wrote on last edited by
          #4

          I'm afraid your comment in that post
          Be aware that this will work with your combo boxes, but not with default generated line edits or the like!
          is what messes it up for me....

          I'm just trying to use a QTableView in a straightforward manner for once (no delegates or proxies, with a couple of text fields) but with no luck

          If you can't say what you mean, you'll never be able to mean what you say.

          1 Reply Last reply
          0
          • H Offline
            H Offline
            hsfougaris
            wrote on last edited by
            #5

            Meanwhile, my solution is something like (inside my manual save function)
            @
            QModelIndex ndx = ui->tableView->currentIndex();
            if (ndx.isValid()) {
            ui->tableView->setCurrentIndex( tbl->index(ndx.row(), 0));
            ui->tableView->setCurrentIndex( tbl->index(ndx.row(), 1));
            }
            @
            which only works if there are at least 2 columns, but at least it works.

            If you can't say what you mean, you'll never be able to mean what you say.

            1 Reply Last reply
            0
            • G Offline
              G Offline
              goetz
              wrote on last edited by
              #6

              Seems a mislanding in the HTML, I wanted to point you to the very first reply in that thread. This works for every type of cell editor. The comment about the combo boxes was related to the code snippets later on.

              http://www.catb.org/~esr/faqs/smart-questions.html

              1 Reply Last reply
              0
              • H Offline
                H Offline
                hsfougaris
                wrote on last edited by
                #7

                Ok... if I understand it correctly though, it can only work with subclassing?

                If you can't say what you mean, you'll never be able to mean what you say.

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  goetz
                  wrote on last edited by
                  #8

                  No. Just call that mentioned endEdit() method whenever you want to be sure that all editors are closed (eg. in a save or check method).

                  http://www.catb.org/~esr/faqs/smart-questions.html

                  1 Reply Last reply
                  0
                  • H Offline
                    H Offline
                    hsfougaris
                    wrote on last edited by
                    #9

                    You are talking about QTableView's endEdit() function?
                    Isn't that a protected function (so I need to subclass QTableView)?

                    If you can't say what you mean, you'll never be able to mean what you say.

                    1 Reply Last reply
                    0
                    • G Offline
                      G Offline
                      goetz
                      wrote on last edited by
                      #10

                      No, I talk about a method in another class. You can happily name it like you want, eg.

                      @
                      void closeThatFunkyEditorBecauseQtDoesNot();
                      @

                      http://www.catb.org/~esr/faqs/smart-questions.html

                      1 Reply Last reply
                      0
                      • H Offline
                        H Offline
                        hsfougaris
                        wrote on last edited by
                        #11

                        I'm sorry for insisting, but I don't understand something.
                        You are talking about a function that contains
                        @
                        void AnyClass::endEdit()
                        {
                        QModelIndex index = myTblVw->currentIndex();
                        myTblVw->currentChanged( index, index );
                        }
                        @
                        How do I get access to the auto-generated text edit of the QTableView, so I can wire it to this slot?
                        Also, isn't currentChanged protected too?

                        If you can't say what you mean, you'll never be able to mean what you say.

                        1 Reply Last reply
                        0
                        • G Offline
                          G Offline
                          goetz
                          wrote on last edited by
                          #12

                          You do not wire this to a signal of the editor. Just call this method in your slot connected to the save button before you actually do the save.

                          http://www.catb.org/~esr/faqs/smart-questions.html

                          1 Reply Last reply
                          0
                          • H Offline
                            H Offline
                            hsfougaris
                            wrote on last edited by
                            #13

                            I must be missing something very obvious here, because it's not working for me.

                            Inside my Qt class that owns the QTableView (say it's a variable named myTblVw) , I can't call
                            myTblVw->currentChanged(...) from my save() slot because it's a protected method.

                            So you are saying I should create another class deriving from anything, and write a function like in the previous posts? How does that class get access to the QTableView? Even if I were to pass a pointer to myTblVw, it still won't be able to call the protected method.
                            How is this going to work without subclassing?

                            If you can't say what you mean, you'll never be able to mean what you say.

                            1 Reply Last reply
                            0
                            • G Offline
                              G Offline
                              goetz
                              wrote on last edited by
                              #14

                              Yes, you're right, sorry. I have it in a QXyzView subclass and thus can call slot currentChanged() this way.

                              http://www.catb.org/~esr/faqs/smart-questions.html

                              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