Unsolved dir.mkdir not creating a directory
-
void MainWindow::on_pushButton_clicked() { if(currentDir.isEmpty()) return; qDebug() << currentDir; //"C:/Program Files" QDir dir(currentDir); if(!dir.exists()) return; bool ok; QString name = QInputDialog::getText(this, "Folder name", "Enter a folder name", QLineEdit::Normal, QDir::home().dirName(), &ok); if(ok && !name.isEmpty()) if(dir.mkdir(name)) qDebug() << "Folder created: " << name; else qDebug() << "Folder not created"; }
It outputs that the folder was successfully created but I don't see one when I go to C:/Program Files
What could be the problem? -
It works for me i.e. it prints "folder not created".
Writing to "Program Files" requires administrative privileges. Are you running your program as admin? -
Ah, it does create folders in other directories. Although it is weird that it always outputs that the folder was created even if it wasn't.
Thanks. -
Sounds weird indeed. What OS and Qt version are you running?