Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Call for Presentations - Qt World Summit

    Set a QString data in a QSqlRelationalTableModel

    General and Desktop
    2
    5
    1034
    Loading More Posts
    • 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
      Basch006 last edited by

      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 Reply Quote 0
      • Jeroentjehome
        Jeroentjehome last edited by

        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 Reply Quote 0
        • B
          Basch006 last edited by

          @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 Reply Quote 0
          • Jeroentjehome
            Jeroentjehome last edited by

            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 Reply Quote 0
            • B
              Basch006 last edited by

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

              I'll test with the Debug one more time.

              1 Reply Last reply Reply Quote 0
              • First post
                Last post