PDA

View Full Version : How do I create a directory ?



Sergex
5th April 2013, 15:16
Hello,

I have an application in which I need to save files into a directory. First I have a QDialog in which I fill in some information through combo-boxes and Line edits and when hitting the OK button I want to create a directory with a specified name in the home directory.

So if I set the name to "myDirectory" I want to be able to see (in Windows explorer for example) a folder created with the name "myDirectory" to later save files into that folder. The whole path would be C:/Users/home/myDirectory

I tried doing something like this:




void myDialog::createDirectory()
{
QString filePath = QDir::homePath() + "/" + m_Name;

QDir dir;
dir.mkdir(m_Name);
}


What am I missing to make this work??

Thank you.

Ashkan_s
5th April 2013, 15:55
try QDir::mkpath

amleto
5th April 2013, 21:02
Hello,

I have an application in which I need to save files into a directory. First I have a QDialog in which I fill in some information through combo-boxes and Line edits and when hitting the OK button I want to create a directory with a specified name in the home directory.

So if I set the name to "myDirectory" I want to be able to see (in Windows explorer for example) a folder created with the name "myDirectory" to later save files into that folder. The whole path would be C:/Users/home/myDirectory

I tried doing something like this:




void myDialog::createDirectory()
{
QString filePath = QDir::homePath() + "/" + m_Name;

QDir dir;
dir.mkdir(m_Name);
}


What am I missing to make this work??

Thank you.

Judging from the manual (QDir.html#mkdir), "you're doing it wrong".


void myDialog::createDirectory()
{
QString filePath = QDir::homePath();

QDir dir(filePath);
dir.mkdir(m_Name);
}

anda_skoa
6th April 2013, 15:47
void myDialog::createDirectory()
{
QString filePath = QDir::homePath();

QDir dir(filePath);
dir.mkdir(m_Name);
}


Or just


QDir::home().mkdir(m_Name);


Cheers,
_