robgeek
20th January 2020, 23:28
Hello!
I'm trying to set a rootpath to see files and folders in a QTreeView but no matter what string I set to rootpath I always see the same root folder "/" in my case because I'm using linux.
I would like to set "/media/backup" but when I start the program it always shows my "/". Even if I pass to setRootPath("") it shows me the same folder.
Why and how can I fix this?
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QFileSystemModel>
#include <QMainWindow>
#include <QtCore>
#include <QtGui>
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
private slots:
void on_buttonCompress_clicked();
void on_buttonExtract_clicked();
private:
Ui::MainWindow *ui;
QFileSystemModel *fsModel;
};
#endif // MAINWINDOW_H
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
const QString rootPath = "/media/backup/";
fsModel = new QFileSystemModel(this);
fsModel->setRootPath(rootPath);
ui->treeView->setModel(fsModel);
}
//...
I'm trying to set a rootpath to see files and folders in a QTreeView but no matter what string I set to rootpath I always see the same root folder "/" in my case because I'm using linux.
I would like to set "/media/backup" but when I start the program it always shows my "/". Even if I pass to setRootPath("") it shows me the same folder.
Why and how can I fix this?
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QFileSystemModel>
#include <QMainWindow>
#include <QtCore>
#include <QtGui>
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
private slots:
void on_buttonCompress_clicked();
void on_buttonExtract_clicked();
private:
Ui::MainWindow *ui;
QFileSystemModel *fsModel;
};
#endif // MAINWINDOW_H
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
const QString rootPath = "/media/backup/";
fsModel = new QFileSystemModel(this);
fsModel->setRootPath(rootPath);
ui->treeView->setModel(fsModel);
}
//...