1

How can i ask one user to create a folder through one dialog box in qt .

So that whatever the name the user has given in the dialog box ( in a specific location,

for eg. c:/user/...) the folder will be created in that location and if the folder is

alreday present with the specific name in that location then replacement shall be done .

Viku
  • 2,845
  • 4
  • 35
  • 63
  • Did you try to write anything? Where do you have problem? – Kamil Klimek Jun 14 '12 at 08:59
  • Please take a look at other questions here first. This looks like it should answer your question http://stackoverflow.com/questions/2241808/checking-if-a-folder-exists-and-creating-folders-in-qt-c – oggmonster Jun 14 '12 at 09:25
  • Please refer to the QDir Class Reference http://doc.qt.nokia.com/4.7-snapshot/qdir.html#setPath. It appears that what you need is QDir::setPath() and QDir::mkdir(). Also, Qt Documents is always the first place to go when encountering a problem. – user957121 Jun 14 '12 at 10:25
  • Thankx for your reply .. @oggmonster - i have been through that link , which u have provided here .. But what i want to know is how to create a folder using one dialogbox(like we use for creating one file by using QFiledialog::getsaveFilename()) – Viku Jun 14 '12 at 10:46
  • You need to specify your question in more detail. But what I think you need to do is use the QDir::mkpath("your file path") in response to some user action. You haven't described what user action that is – oggmonster Jun 14 '12 at 12:11
  • @oggmonster here the user action is to create one folder . There is one button in my project , so when the user click that button at that time one dialog box should open where the user may allow to give the folder name , through that dialog box the user allow to select the location , like whether he wants to create the folder in desktop or c drive or d drive . if the folder is already present in that specific location then it will ask for replacement to the user , if the user press yes then it will replace that folder or else the folder is not getting replaced . – Viku Jun 14 '12 at 13:57

1 Answers1

1

A usual GUI approach to this would be to use QFileDialog::getExistingDirectory(QWidget* parent, const QString& caption, const QString& dir, Options options) to present a directory selection dialog to the user. Have the output of the selection displayed a in QLineEdit, so if the user wants to create a new subdirectory they can append new folder names.

Then as the comments to your question state, use QDir to determine if the directory is existing or not - and make it if it isn't.

cmannett85
  • 21,725
  • 8
  • 76
  • 119