QDir mkdir with absolutepath

Guillaume picture Guillaume · Mar 9, 2012 · Viewed 45.4k times · Source

I have problem with the creation of dir with Qt. I would like to create a dir in documents'dir so, I make some things like that :

QString path("C:/Users/Me/Documents/MyApp/profiles/");
Qdir dir = QDir::root();
dir.mkdir(path);

But that doesn't work! I have test with "/" and "\" for the separators but in the two cases that not work.

How I can create my dir?

Thank you.

Answer

yerlilbilgin picture yerlilbilgin · Jul 1, 2013

You can do this:

QDir dir(path);
if (!dir.exists()){
  dir.mkdir(".");
}