Results 1 to 12 of 12

Thread: Setting QSqlTableModel from c++ to .qml tableView

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: Setting QSqlTableModel from c++ to .qml tableView

    Quote Originally Posted by heczaco View Post
    adding the columns makes no difference :/
    Without columns it wil definitely be empty, because then you don't thell the view which property to show in which column.

    And you forgot to post the code with coumns.

    Quote Originally Posted by mayrhofer
    and QSqlTableModel is a subclass of QAbstractTableModel... is that wrong?
    So object is a plain QSqlTableModel not some application specific subclass?

    Cheers,
    _

  2. #2
    Join Date
    Jan 2016
    Posts
    6
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Setting QSqlTableModel from c++ to .qml tableView

    Well, for the columns I tried many ways, with rolenames with rolenames equal as the ones i'd get if I create the table from c++ (as in the code in the original post), with titles, no titles, etc. None seems to work :/

    Qt Code:
    1. TableView{
    2. id: table;
    3. width: parent.width -100
    4. height: parent.height -200
    5. anchors.horizontalCenter: parent.horizontalCenter
    6. anchors.top: parent.top
    7. anchors.topMargin: 90
    8. model: eventModel.getTData(GData.tName, table);
    9. TableViewColumn{
    10. role:"time"
    11. title:"time"
    12. }
    13. TableViewColumn{
    14. role:"var1"
    15. title:"var1"
    16. }
    17. TableViewColumn{
    18.  
    19. }
    20. TableViewColumn{
    21. role:"var3"
    22. }
    23. }
    To copy to clipboard, switch view to plain text mode 

    The table model is a plain QSqlTableModel, does the problem lie in there?, 'cause it seems to work just fine for a table created in c++

    Capture.jpg

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: Setting QSqlTableModel from c++ to .qml tableView

    The only roles you have are the ones defined in QAbstractItemModel, e.g. "display".
    None of your columns use existing role names, so it is no suprise that the table is empty.

    Cheers,
    _

  4. #4
    Join Date
    Jan 2016
    Posts
    6
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Setting QSqlTableModel from c++ to .qml tableView

    thanks, in debug time I saw that the role names were totally different to the headers (I thought set headerdata would change both) it shows data now that I change the roles to the names I saw on debug time, but I'm not able to set the roles from c++ to what I want, could you help me get in the right direction?

  5. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: Setting QSqlTableModel from c++ to .qml tableView

    QAbstractItemModel::roleNames() allows you to map custom roles name to custom role values.

    So you specifiy some integer role values for the data you want to get (usually usign an enum) and then map these values to the strings that you want to use on the QML side.

    Cheers,
    _

  6. #6
    Join Date
    Jan 2016
    Posts
    6
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Setting QSqlTableModel from c++ to .qml tableView

    Hi, I'm only able to display the first column with the Display Role, Can I only use that role? If so, how do I get the other columns to show?

  7. #7
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: Setting QSqlTableModel from c++ to .qml tableView

    Quote Originally Posted by heczaco View Post
    Hi, I'm only able to display the first column with the Display Role
    Unsurprisingly, since that is one of the standard roles that is also in the standard role name mapping.

    Quote Originally Posted by heczaco View Post
    Can I only use that role?
    Of course not, that would make models pretty useless.

    Quote Originally Posted by heczaco View Post
    If so, how do I get the other columns to show?
    See comment #10.

    Cheers,
    _

Similar Threads

  1. Default sort in QSqlTableModel and tableview
    By rdjenner in forum Qt Programming
    Replies: 0
    Last Post: 17th August 2011, 17:15
  2. Replies: 7
    Last Post: 30th June 2011, 10:16
  3. Replies: 0
    Last Post: 17th June 2011, 09:11
  4. QSqlTableModel Setting Current Row?
    By fifth in forum Qt Programming
    Replies: 4
    Last Post: 15th June 2008, 13:44
  5. setting UserRole data in QSqlTableModel
    By orgads in forum Qt Programming
    Replies: 1
    Last Post: 2nd June 2008, 09:40

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.