Results 1 to 5 of 5

Thread: Inner join use QSqlTableModel

  1. #1
    Join Date
    Sep 2015
    Posts
    4
    Qt products
    Platforms
    Windows

    Default Inner join use QSqlTableModel

    Hi everyone,

    I am working on a music player and one thing I have been struggling with is QSql database. Right now I have my main library database with primary key ID. I want to drag and drop songs to my playlist which is currently a :memory: database. The information is exactly the same except the primary key of the playlist is playlist_ID. Currently I am copying all the the records from the library to the playlist. This is okay when not to much is being moved, but if you want to load the whole library (e.g. shuffle mode) hangs for longer than I like.

    I am wondering if it is possible to do a full inner join (I would use a table in the library database instead then) such that my playlist table only contains

    playlist_ID, ID

    and the rest like title, artist, album, etc... are filled in by the join. The goal is to only have to copy over the ID's during drag events instead of all 35 or so fields per record. I looked into using QSqlQuery model a but I want to be able to edit the fields from the playlist and it seems like there must be a better solution than just recreating QSqlTableDatabase.

    Thanks!

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

    Default Re: Inner join use QSqlTableModel

    Maybe with a QSqlRelationalTableModel?

    Cheers,
    _

  3. #3
    Join Date
    Sep 2015
    Posts
    4
    Qt products
    Platforms
    Windows

    Default Re: Inner join use QSqlTableModel

    Quote Originally Posted by anda_skoa View Post
    Maybe with a QSqlRelationalTableModel?

    Cheers,
    _
    I looked at that, but from what I could gather, it is strictly used on a 1 foreign key:1 value basis. I don't see where it allows joining multiple columns, even though there is clearly the joinMode enum.

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

    Default Re: Inner join use QSqlTableModel

    Hmm, ok, haven't use that model myself yet.

    If it can't be used, then you'll have to implement a table model yourself by deriving from QAbstractTableModel and implementing columnCount(), rowCount() and data() and using QSqlQuery internally.

    Cheers,
    _

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Inner join use QSqlTableModel

    The docs contain an exampe editable QSqlQueryModel that might serve as a starting point.

    Another approach might be to use a model that lazy loads the entry details only when first requested. Drop would insert only the id, and data() would fetch the details of the entry (possibly cache them) when a view/consumer asked for the values.

Similar Threads

  1. join is not working
    By godlesplay in forum Newbie
    Replies: 7
    Last Post: 26th January 2016, 11:51
  2. Qwt Join x and y axis
    By sonulohani in forum Qwt
    Replies: 0
    Last Post: 18th July 2012, 09:51
  3. Replies: 8
    Last Post: 30th March 2011, 21:06
  4. Join the QtBrasil
    By ross in forum General Discussion
    Replies: 0
    Last Post: 9th August 2010, 19:04
  5. Thread does not join
    By AlphaWolf in forum Qt Programming
    Replies: 1
    Last Post: 22nd April 2009, 09:09

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.