Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Double the column in QSqlTableModel
Qt 6.11 is out! See what's new in the release blog

Double the column in QSqlTableModel

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 2.6k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Hi , can you help me double the coumn in QSqlTableModel.

    [code]
    QTableView table;
    QSqlTableModel model;

    model.setTable("User");
    model.select();
    
    table.setModel(&model);
    
    table.show();
    

    [/code]

    Table "User" have 2 column (Id, name) how i can set in my model to have 3 column (id,id, name)
    coumn id is double

    Its can by in QSqlTableModel or QSqlRelationalTableModel.

    [edit: fixed typo in title, eddy]

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      I'm not quite sure what you mean by "column id is double". Can you show you SQL table structure and exactly what you want please?

      It may be that you need to use QSqlQueryModel instead of QSqlTableModel.

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        its simple.
        I have 1 table user (id, name)
        i create QSqlRelationalTableModel and QSqlRelationalTableModel::setTable (user).
        Now my model have (id,name).
        To add relationships i need 1 colum , but i want add 2 relationships so i need 2 column id (id (relationships), id(relationships), name)

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          So in that case you must have additional tables in order to make relationships to them but I think I see what you are wanting now.

          It looks like QSqlRelationalTableModel will not do what you want on it's own as it only uses the columns in the table that are already present. One way around this would be to create a view in your database that contains the replicated id column and then use this in your QSqlRelationalDatabaseModel.

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            ok, but if i make view in my table and conect QSqlRelationalTableModel it will by editable ??

            1 Reply Last reply
            0
            • ? Offline
              ? Offline
              A Former User
              wrote on last edited by
              #6

              Ah you never said you wanted it to be editable. In that case, you will likely be better off subclassing from QSqlQueryModel to make that editable. Then you can pass in an arbitrary query but it is down to you to do the "right thing" when the user edits the table.

              1 Reply Last reply
              0
              • ? Offline
                ? Offline
                A Former User
                wrote on last edited by
                #7

                I make View , and QSqlRelationalTableModel::SetTable(This_View), and its work ;) its editable ;) thx for help

                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
                • Unsolved