私がやろうとしていること: QFileSystemModel の setData とデータを上書きして、表示されているディレクトリに画像のキャッシュを実装します。
テスト目的で QListView を使用します。
関連するコードは次のとおりです。
親として QFileSystemModel を持つ私のクラス:
.h ファイル:
#ifndef QPICSINFILESYSTEMMODEL_H
#define QPICSINFILESYSTEMMODEL_H
#include <QFileSystemModel>
#include <QCache>
#include <QDebug>
/* This Model holds all Picturefiles with a cached QPixmap of
* them.
*/
class PicsInFileSystemModel : public QFileSystemModel
{
public:
PicsInFileSystemModel();
QVariant data (const QModelIndex & index, int role);
private:
QCache<qint64,QPixmap> *cache; //Cache for the pictures
};
#endif // QPICSINFILESYSTEMMODEL_
.cpp ファイル:
#include "PicsInFileSystemModel.h"
PicsInFileSystemModel::PicsInFileSystemModel()
{
QStringList myFilter;
this->setFilter(QDir::Files | QDir::AllDirs);
this->setRootPath(QDir::rootPath());//QDir::homePath());
myFilter << "jpeg" << "jpg" << "png";
//this->setNameFilters(myFilter);
}
/* Reimplement data to send the pictures to the cache */
QVariant PicsInFileSystemModel::data ( const QModelIndex & index, int role = Qt::DisplayRole ) {
qDebug() << "index: " << index << "role: " << role;
return ((QFileSystemModel)this).data(index,role);
}
オブジェクトの呼び出し方法:
pics = new PicsInFileSystemModel;
form->listViewPictures->setModel(pics);
form->listViewPictures->setRootIndex(pics->index(
"mypath"));
ここに質問があります。私の意見では、ビューがモデルにアクセスすると、多くのデバッグ出力が表示されるはずです。しかし、何もありません。私が間違っていることを知っている人はいますか?
ありがとう!
編集:答えはうまくいきます。私もこれを変更しなければなりませんでした
return ((QFileSystemModel)this).data(index,role);
の中へ
QFileSystemModel::data(index,role))