hi
when i clicked "Create Dir" button...
Why is this program not working?
QDir.jpg
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QDirModel>
namespace Ui {
class MainWindow;
}
{
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= 0);
~MainWindow();
private slots:
void on_pushButton_clicked();
void on_pushButton_2_clicked();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QDirModel>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void on_pushButton_clicked();
void on_pushButton_2_clicked();
private:
Ui::MainWindow *ui;
QDirModel *model ;
};
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QInputDialog>
#include <QString>
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
model->setReadOnly(false);
model
->setSorting
(QDir::DirsFirst |QDir
::Name |
QDir::IgnoreCase);
ui->treeView->setModel(model);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
//Create
if(!index.isValid())
return;
if(!name.isEmpty())
return ;
model->mkdir(index,name);
}
void MainWindow::on_pushButton_2_clicked()
{
//Delete
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QInputDialog>
#include <QString>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
model = new QDirModel(this) ;
model->setReadOnly(false);
model->setSorting(QDir::DirsFirst |QDir::Name | QDir::IgnoreCase);
ui->treeView->setModel(model);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
//Create
QModelIndex index = ui->treeView->currentIndex();
if(!index.isValid())
return;
QString name = QInputDialog::getText(this,"Name","Enter a name :");
if(!name.isEmpty())
return ;
model->mkdir(index,name);
}
void MainWindow::on_pushButton_2_clicked()
{
//Delete
}
To copy to clipboard, switch view to plain text mode
Bookmarks