QDir mkdir with absolutepath

穿精又带淫゛_ 提交于 2019-12-05 00:48:14

Try to use QDir::mkpath as dir.mkpath(path);

You can do this:

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

QDir dir = QDir::root() creates an instance of QDir configured to point to root and copies that setting to dir. To avoid the extra copy and code , you can use QDir dir(QDir::root);. On Windows it will point to the root of the system drive, usually C:\.

dir.mkdir(path); will attempt to create a subdirectory named path in the currently configured directory (root). This method expects a single directory name and not a full path. It also returns a bool result that you should be checking.

You probably want to be calling dir.mkpath(path) which will attempt to create the subdirectory specified along with all the necessary parent directories leading up to it. Again, you should check the result to see if it was successful.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!