QtCreator 的ui->treeView加载QFileSystemModel model却不显示
大家好:
我的UI中有一个TreeView,我想让他显示本地所有磁盘文件,具体代码如下:
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
//开始加载本地文件系统
QFileSystemModel model;
model.setRootPath("C:");
ui->treeView->setModel(&model);
ui->treeView->showColumn(1);
// Demonstrating look and feel features
treeView->setAnimated(false);
treeView->setIndentation(20);
treeView->setSortingEnabled(true);
treeView->setWindowTitle(QObject::tr("Dir View"));
#if defined(Q_OS_SYMBIAN) || defined(Q_WS_MAEMO_5)
ui->treeView->showMaximized();
#else
ui->treeView->resize(640, 480);
ui->treeView->show();
#endif
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
//开始加载本地文件系统
static QFileSystemModel model;
model.setRootPath("C:");
ui->treeView->setModel(&model);
ui->treeView->showColumn(1);
// Demonstrating look and feel features
treeView->setAnimated(false);
treeView->setIndentation(20);
treeView->setSortingEnabled(true);
treeView->setWindowTitle(QObject::tr("Dir View"));
#if defined(Q_OS_SYMBIAN)
[解决办法]
defined(Q_WS_MAEMO_5)
ui->treeView->showMaximized();
#else
ui->treeView->resize(640, 480);
ui->treeView->show();
#endif
}