QDir is a class in the Qt library that provides access to the file system. The relativeFilePath() method is used to return a QString that represents the relative path of the directory or the file from the current directory path.
Example 1:
QString currentDir = QDir::currentPath(); QString filePath = "/home/user/Pictures/image.jpg"; QString relativePath = QDir::relativeFilePath(filePath, currentDir); // relativePath will be "Pictures/image.jpg"
In this example, we set the current directory as the base directory and then define a file path. The relativeFilePath() method is used to get the relative path of this file from the current directory. The returned value will be a QString that represents the relative path of the file.
Package/library: Qt library
Example 2:
QDir dir("myDir"); QDir subDir("myDir/mySubDir/"); QString relativePath = QDir::relativeFilePath(subDir, dir); // relativePath will be "mySubDir"
In this example, we create two QDir objects. The first QDir is set as the parent directory, and the second QDir is set as the child directory. We use the relativeFilePath() method to get the relative path of the child directory from the parent directory. The returned value will be a QString that represents the relative path of the child directory.
Package/library: Qt library
C++ (Cpp) QDir::relativeFilePath - 30 examples found. These are the top rated real world C++ (Cpp) examples of QDir::relativeFilePath extracted from open source projects. You can rate examples to help us improve the quality of examples.