How to link two data sources with QListView?



  • 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



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



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



  • 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



  • [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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.