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. Set a QString data in a QSqlRelationalTableModel

Set a QString data in a QSqlRelationalTableModel

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 1.3k 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.
  • B Offline
    B Offline
    Basch006
    wrote on last edited by
    #1

    Hi everybody !

    I got a little problem with my model (and I think the problem would be the same with another kind of model).

    I have a QString to write in my model.
    For exemple, I have already some data in my model, got from a database. Here, a transportation (destination, product, vehicule). I added a column in this model and I want to write something (list of drivers related to this transport) in theses items. I have my QString with the good names etc, but I can't wite it in the model, the items stay withe, nothing written in it.

    I tried to use setData() but it doesn't seem to work :/

    If somebody has an idea, it would be cool ^^
    Thanks anyway for the attentions.

    1 Reply Last reply
    0
    • JeroentjehomeJ Offline
      JeroentjehomeJ Offline
      Jeroentjehome
      wrote on last edited by
      #2

      Just asking the obvious, but are the flags for the column set to be editable in your model. The flags in the model determine the way the view handles different columns. If you want to make it fancy you could also add a delegate (QComboBox e.g.).
      Then when you are finished editing the string the setData will be called. You have to store the data in your model yourself.

      Greetz, Jeroen

      1 Reply Last reply
      0
      • B Offline
        B Offline
        Basch006
        wrote on last edited by
        #3

        @Qt::ItemFlags TableSql::flags(QModelIndex index)
        {
        Qt::ItemFlags flags = QAbstractTableModel::flags(index);
        if (index.column() == 4)
        {
        flags = Qt::ItemIsEditable;
        return flags;
        }
        return QAbstractTableModel::flags(index);
        }@

        I tried this on my model class, but nothing changed.

        My call of setData() :
        @modelGererTransports->setData(vueGererTransports->model()->index(ligne, 4), chauffeurs, Qt::EditRole);@

        Where modelGererTransports = TableSql (inhérits from QSqlRelationalTableModel), vueGererTransports = QTableView and chauffeurs = QString

        1 Reply Last reply
        0
        • JeroentjehomeJ Offline
          JeroentjehomeJ Offline
          Jeroentjehome
          wrote on last edited by
          #4

          Hi,
          Maybe to solve this problem it's best to use a 'default' QTableView to display the data. That way you're able to pinpoint the problem. Maybe your view implementation is not correct, so the call to setData is wrong. When you use the default View it will all go in the normal way as it should. We can go from there.
          Also, debug the flags and setData functions. Check out what happens.

          Greetz, Jeroen

          1 Reply Last reply
          0
          • B Offline
            B Offline
            Basch006
            wrote on last edited by
            #5

            But, I'm using the "default" QTableView (with or without delegate) ^^"

            I'll test with the Debug one more time.

            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