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. How to link two data sources with QListView?

How to link two data sources with QListView?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 3.8k 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.
  • Z Offline
    Z Offline
    zither
    wrote on last edited by
    #1

    Dear all,

    I would like to know how to set two data sources with QListView.
    I am facing that problem.
    Firstly, I used QSqlQueryModel as a data source for QListView.

    @QSqlQueryModel sqlModel;
    sqlModel.setQuery(SELECT * FROM.....);
    myListView.setModel(sqlModel);@

    Later, myListView need to add another data source from XML parser.
    I would like to do.
    @
    myListView.addRow(myXMLdataColumn1, Colunm2,...);@

    But both of them has same data structure (same columns)

    Thanks you, all

    1 Reply Last reply
    0
    • I Offline
      I Offline
      itwiz
      wrote on last edited by
      #2

      In my opinion you should you should write your own QAbstractItemModel derived model which should combine QSqlQueryModel and XML data.This new model should be passed to QListView.

      1 Reply Last reply
      0
      • L Offline
        L Offline
        lgeyer
        wrote on last edited by
        #3

        You cannot use multiple models on a view.

        However, you can create your on QAbstractItemModel or QProxyModel which supports mutiple source models (which basically boils down to index mapping).

        Be aware that working with SQL models can be tricky, as model metadata such as QSqlQueryModel::rowCount() might report inaccurate data (depending on the supported features of your underlying database).

        You also might consider just feeding a QStandardItemModel with the values from your source models but doing so you will lose all the advantages of the source models (ie. caching) - which might lead to serious performance implications.

        1 Reply Last reply
        0
        • Z Offline
          Z Offline
          zither
          wrote on last edited by
          #4

          Thanks for all advices.
          Yes...

          I made myModel & set to QListView.
          It lead to significant performance.

          Previously I used,
          @QListView.setModel(QSqlQueryModel);@

          Then, I made myModel from QStandardItemModel to accept two data sources.
          @QListView.setModel(QStandardItemModel);@

          although, tested with same data, 2nd method caused very bad performance.
          During my debugging with timer, it showed that same result upto QListView.setModel();

          I thought that, bad performance may be during paint event of QListView.
          Is it correct?

          How can I fix that?

          Thanks

          1 Reply Last reply
          0
          • L Offline
            L Offline
            lgeyer
            wrote on last edited by
            #5

            [quote author="zither" date="1310885907"]I thought that, bad performance may be during paint event of QListView. Is it correct?[/quote]

            No.

            [quote author="zither" date="1310885907"]How can I fix that?[/quote]

            You can't. See "here":http://developer.qt.nokia.com/forums/viewthread/7835/#46011.

            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