QListWidget performace



  • I need to clear and repopulate this widget many times

    first using:

    ui->resultList->clear();

    and then:

    ui->resultList->addItem(new QListWidgetItem(""));

    there is a noticeable performance degradation of addItem method after some clear calls



  • a perfectly normal working, no problem


  • Moderators

    -Perhaps you would have better luck with a QListView, rather than a QListWidget.-

    [Edit: On second thought, maybe not.]



  • disable updates while clearing and repopulating. See setUpdatesEnabled



  • [quote author="mlong" date="1354218238"]Perhaps you would have better luck with a QListView, rather than a QListWidget.
    [/quote]

    I switchet to QlistView and I used this model class
    @
    #ifndef NETWORK_TESTS_RESULT_MODEL_H
    #define NETWORK_TESTS_RESULT_MODEL_H

    #include <QAbstractListModel>

    class QMimeData;

    class resultListModel : public QAbstractListModel
    {
    Q_OBJECT

    public:
    resultListModel(QObject *parent = 0);
    ~resultListModel();

     void addResult(const QString &postation);
     bool setData(const QModelIndex &index, const QVariant &val,int role);
     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
     bool removeRows(int row, int count, const QModelIndex &parent);
     int rowCount(const QModelIndex &parent) const;
     void clear();
    

    private:
    QPixmap *IdIcon;
    QList<QString> *postationNames;
    QList<QString> *hardwareIds;
    QList<QPixmap> *hardwareImages;
    QList<QString> *hardwareNames;
    QList<QString> *results;
    };

    #endif // NETWORK_TESTS_RESULT_MODEL_H
    @
    unfortunately there is no improvements on performance

    now I'm trying to use setUpdatesEnabled

    thanks for help



  • Using Qts Model-View-Classes for performance improvement usually requires you to write your own data model which takes into account the nature of your data to get the performance improvement. Sometimes you'll even want to write your own views. Of course, that's a non-trivial task. But if using off-the-shelf model-view components (especially Qts), you generally degrade performance (with the benefit of more flexibility and possibly a less entangled application design compared to the non-mvc approach).


  • Moderators

    I agree with DerManu.



  • thanks for replys Qt is a great work.
    I changed strategy and now all works fine


Log in to reply
 

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