Hi I have this problem:
I need to open (and delete) a file (it's displayed on a QTreeView) with a button.
At the moment I can only do this operation with a double click, but is not enough.
This is my header:
#ifndef EDITOR_H
#define EDITOR_H
#include <QDialog>
#include <QtCore>
#include <QtGui>
#include <QFileSystemModel>
#include <QCoreApplication>
#include <QFile>
namespace Ui {
class editor;
}
{
Q_OBJECT
public:
explicit editor
(QWidget *parent
= 0);
~editor();
private slots:
void on_vistaLista_doubleClicked
(const QModelIndex &index
);
void on_cancellaFileEditor_clicked();
private:
Ui::editor *ui;
QFileSystemModel *model;
};
#endif // EDITOR_H
#ifndef EDITOR_H
#define EDITOR_H
#include <QDialog>
#include <QtCore>
#include <QtGui>
#include <QFileSystemModel>
#include <QCoreApplication>
#include <QFile>
class QString;
class QModelIndex;
namespace Ui {
class editor;
}
class editor : public QDialog
{
Q_OBJECT
public:
explicit editor(QWidget *parent = 0);
~editor();
private slots:
void on_vistaLista_doubleClicked(const QModelIndex &index);
void getDetails(const QModelIndex &index);
void on_cancellaFileEditor_clicked();
private:
Ui::editor *ui;
QFileSystemModel *model;
};
#endif // EDITOR_H
To copy to clipboard, switch view to plain text mode
and the program....
#include "editor.h"
#include "ui_editor.h"
ui(new Ui::editor)
{
ui->setupUi(this);
QString directory
= qApp
->applicationDirPath
() + "/download";
model = new QFileSystemModel(this);
model
->setFilter
(QDir::Files);
ui->vistaLista->setModel(model);
ui->vistaLista->setRootIndex(model->setRootPath(directory));
}
editor::~editor()
{
delete ui;
}
void editor
::on_vistaLista_doubleClicked(const QModelIndex &index
) {
QString url
= model
->fileInfo
(index
).
filePath();
}
{
QString filename
=model
->fileInfo
(index
).
filePath();
ui->labelTemporaneaEditor->setText(filename);
}
void editor::on_cancellaFileEditor_clicked()
{
//????????????????????????????????? ARGHHHHHH ??????????????????
}
#include "editor.h"
#include "ui_editor.h"
editor::editor(QWidget *parent) :
QDialog(parent),
ui(new Ui::editor)
{
ui->setupUi(this);
QStringList lista;
QString directory = qApp->applicationDirPath() + "/download";
model = new QFileSystemModel(this);
model->setFilter(QDir::Files);
ui->vistaLista->setModel(model);
ui->vistaLista->setRootIndex(model->setRootPath(directory));
connect(ui->vistaLista, SIGNAL(clicked(QModelIndex)), this, SLOT(getDetails(QModelIndex)));
}
editor::~editor()
{
delete ui;
}
void editor::on_vistaLista_doubleClicked(const QModelIndex &index)
{
QString url = model->fileInfo(index).filePath();
QDesktopServices::openUrl(QUrl::fromLocalFile(url));
}
void editor::getDetails(const QModelIndex &index)
{
QString filename=model->fileInfo(index).filePath();
ui->labelTemporaneaEditor->setText(filename);
}
void editor::on_cancellaFileEditor_clicked()
{
//????????????????????????????????? ARGHHHHHH ??????????????????
}
To copy to clipboard, switch view to plain text mode
Please help me!!!! Thanks!
Bookmarks