【发布时间】:2014-07-28 12:12:24
【问题描述】:
我正在编写我的第一个 Qt 项目(所以我是这个环境的新手)并且我已经使用 MVC 设计模式构建了这个项目。 这是一个非常基本的笔记管理器/编辑器。我有一个 uiman 类(“Ui Manager”),它负责我的 UI,以及我打开笔记数据库的功能(这只是一个要打开的文本文件列表)
void uiman::openDBDialog(){
QFileDialog dialog;
dialog.setFileMode(QFileDialog::AnyFile);
dialog.setDirectory("/Users/myuserdir/Desktop");
dialog.setFilter(QDir::Files);
dialog.setWindowTitle("Open File");
dialog.setNameFilter("Textie Notes DB(*.db)");
dialog.exec();
QString pathDB = dialog.selectedFiles().first();
model = new notesModel();
model->setNotesDB(new QString(pathDB.toUtf8().constData()));
refreshAll();
}
到目前为止,一切都很好。我采用数据库的路径并将其提供给我的模型,该模型现在应该管理其余部分。
现在,refreshAll() 函数应该获取我打开的列表并将它们显示在我的 QListView 中,但是我无法使用 clear() 和 append() 解析文件并在旅途中附加项目,这与 QListWidget 不同。那么,我该如何从我的文件中构建一个名称向量(我想)并将它们提供给我的 QListView?
对不起,如果我不清楚,但官方文档还不够清楚。
编辑:这是我的模型,nodesmodel,这是代码。
notesModel::notesModel(QObject *parent) :
QFileSystemModel(parent)
{
QStringList noteList;
}
void notesModel::setNotesDB(QString *dbpath){
// open the notes database
databasepath = dbpath;
}
QFile* notesModel::getDB(){
if(this->dbFile == NULL)
this->dbFile = new QFile(databasepath- >toUtf8().constData());
return this->dbFile;
}
【问题讨论】:
-
什么是型号?以及函数 notesModel() 中的内容是什么?
-
能否请您编辑带有 notesModel 详细信息的帖子。在评论中它们不可读。
-
抱歉,我的格式有问题,已在主要问题中修复。
-
请检查此链接是否有帮助:qt-project.org/doc/qt-4.8/…