我是 QT 的新手。我正在尝试创建一个简单的文件系统浏览器。我为模型和视图类创建了一个单独的类。他们来了:
//modelClass.h
#ifndef MODELCLASS_H
#define MODELCLASS_H
#include <QFileSystemModel>
class modelClass: public QFileSystemModel{
Q_OBJECT
public:
modelClass(); //constructor
QFileSystemModel* createModel(); //creates the QFileSystemModel
//public slots:
private:
};
#endif // MODELCLASS_H
//modelClass.cpp
#include "modelClass.h"
modelClass::modelClass(){
createModel(); //calls to function below
}
QFileSystemModel* modelClass::createModel(){
QFileSystemModel* model = new QFileSystemModel;
model->setRootPath("/");
return model;
}
//systemBrowser.cpp
#include "modelClass.h"
#include <QtGui>
int main(int argc, char *argv[]){
QApplication app(argc, argv);
modelClass model();
QTreeView tree;
tree.setModel(&model);
tree.setSortingEnabled(true);
tree.header()->setResizeMode(QHeaderView::ResizeToContents);
tree.resize(640, 480);
tree.show();
return app.exec();
}
在尝试编译它时,我收到错误:
no matching function for call to 'QTreeView::setModel(modelClass(*)())'
candidates are: virtual void QTreeView::setModel(QAbstractItemModel*)*
谁能帮我解决这个错误?我敢肯定它只是我想念的一些简单的东西。谢谢