Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/142.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Qt QFileInfo.isDir()返回错误的结果_C++_Qt4.8 - Fatal编程技术网

C++ Qt QFileInfo.isDir()返回错误的结果

C++ Qt QFileInfo.isDir()返回错误的结果,c++,qt4.8,C++,Qt4.8,我对Qt类QFileInfo有问题,这里是一些代码示例 QString path = "C:\\Some\\Path"; QFileInfo pathFileInfo(path); if (pathFileInfo.isDir()){ qDebug() << "path is dir, cdUp"; pathDir.cdUp(); } else { qDebug() << "path is not dir, getting dir

我对Qt类QFileInfo有问题,这里是一些代码示例

 QString path = "C:\\Some\\Path";
 QFileInfo pathFileInfo(path);
 if (pathFileInfo.isDir()){
     qDebug() << "path is dir, cdUp";
     pathDir.cdUp();
  } else {
      qDebug() << "path is not dir, getting dir";
      pathDir = pathFileInfo.dir();
  }
QString path=“C:\\Some\\path”;
QFileInfo路径FileInfo(路径);
if(pathFileInfo.isDir()){

qDebug()小心反斜杠,它们必须转义。将路径声明替换为:

QString path = "C:\\Some\\Path";
或使用:

QString path = "C:/Some/Path";
希望这能解决您的问题。

“/”“\”这样的斜杠在Linux和Windows中是不同的。您可以使用static方法
QString QDir::toNativeSeparators(const QString&pathName)
为您的平台获取具有正确分隔符的正确路径

那么就这么做吧:

QString path = QDir::toNativeSeperators( "/your/path/here" );
//you can also use path2 instead of path since they are both the same
QString path2 = QDir::toNativeSeperators( "/your\path/here" );
 QFileInfo pathFileInfo(path);
 if (pathFileInfo.isDir()){
     qDebug() << "path is dir, cdUp";
     pathDir.cdUp();
  } else {
      qDebug() << "path is not dir, getting dir";
      pathDir = pathFileInfo.dir();
  }
QString path=QDir::tonativeoperators(“/your/path/here”);
//您也可以使用path2而不是path,因为它们都是相同的
QString path2=QDir::tonativeperators(“/your\path/here”);
QFileInfo路径FileInfo(路径);
if(pathFileInfo.isDir()){

qDebug()如果将路径更改为'QString path=“C:\\Some\\path”;'该怎么办?在示例中,这只是一个输入错误。路径具有正确的转义,而不是硬编码