Results 1 to 4 of 4

Thread: QDir

  1. #1
    Join Date
    Mar 2013
    Posts
    45
    Thanks
    23
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default QDir

    hi
    when i clicked "Create Dir" button...
    Why is this program not working?

    QDir.jpg

    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5. #include <QDirModel>
    6.  
    7. namespace Ui {
    8. class MainWindow;
    9. }
    10.  
    11. class MainWindow : public QMainWindow
    12. {
    13. Q_OBJECT
    14.  
    15. public:
    16. explicit MainWindow(QWidget *parent = 0);
    17. ~MainWindow();
    18.  
    19. private slots:
    20. void on_pushButton_clicked();
    21.  
    22. void on_pushButton_2_clicked();
    23.  
    24. private:
    25. Ui::MainWindow *ui;
    26. QDirModel *model ;
    27.  
    28. };
    29.  
    30. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3. #include <QInputDialog>
    4. #include <QString>
    5.  
    6. MainWindow::MainWindow(QWidget *parent) :
    7. QMainWindow(parent),
    8. ui(new Ui::MainWindow)
    9. {
    10. ui->setupUi(this);
    11. model = new QDirModel(this) ;
    12. model->setReadOnly(false);
    13. model->setSorting(QDir::DirsFirst |QDir::Name | QDir::IgnoreCase);
    14. ui->treeView->setModel(model);
    15. }
    16.  
    17. MainWindow::~MainWindow()
    18. {
    19. delete ui;
    20. }
    21.  
    22. void MainWindow::on_pushButton_clicked()
    23. {
    24. //Create
    25. QModelIndex index = ui->treeView->currentIndex();
    26. if(!index.isValid())
    27. return;
    28. QString name = QInputDialog::getText(this,"Name","Enter a name :");
    29. if(!name.isEmpty())
    30. return ;
    31. model->mkdir(index,name);
    32. }
    33.  
    34. void MainWindow::on_pushButton_2_clicked()
    35. {
    36. //Delete
    37. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QDir

    Why is this program not working?
    I am not sure how you expect us to know: you have not told us what you expect it to do, or in what way it is "not working."

    Attempting to create a directory with no name is unlikely to be useful. Providing a name is going to do nothing.

  3. #3
    Join Date
    Mar 2013
    Posts
    45
    Thanks
    23
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QDir

    i when clicked "Create Dir" button, then i write a name, folder not created

  4. #4
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QDir

    Qt Code:
    1. if(!name.isEmpty())
    2. return ;
    3. model->mkdir(index,name);
    To copy to clipboard, switch view to plain text mode 


    if(!name.isEmpty())
    this should be like this
    if(name.isEmpty()).

    When the name is not empty, you need to create the folder.

    you need to remove the ! before name. isEmpty will return true when the string is empty.


    hope it helps,
    bala

  5. The following user says thank you to BalaQT for this useful post:

    smemamian (2nd April 2013)

Similar Threads

  1. QListView and QDir
    By Yayati.Ekbote in forum Qt Programming
    Replies: 5
    Last Post: 26th March 2010, 11:45
  2. QDir mkpath
    By yazwas in forum Qt Programming
    Replies: 1
    Last Post: 28th August 2009, 21:21
  3. Help with QDir model
    By allstar in forum Qt Programming
    Replies: 1
    Last Post: 15th December 2007, 15:31
  4. QDir Subclassing
    By Oleg in forum Qt Programming
    Replies: 9
    Last Post: 31st October 2007, 12:03
  5. Is it me or QDir?
    By Morea in forum Qt Programming
    Replies: 1
    Last Post: 29th June 2007, 23:06

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.