Note: do not get tempted by the similarly called baseName() and completeBaseName() in Qt as they are not the same. The Qt and Glib developers decided to use different terms for the same things.
Also, even this is not the same because it will not behave the same way for empty file names or those which end with a slash.
Returns the file's path. This doesn't include the file name.
Note that, if this QFileInfo object is given a path ending in a slash, the name of the file is considered empty and this function will return the entire path.
Note: absolutePath() or canonicalPath() will not work because they will return absolute paths, whereas the glib variant returns relative paths.
strdup
Just use std::string, std::array or QByteArray. Do not get tempted that QString would be the same. It simply is not because that would have the UTF overhead, too, among other things.
There really are not direct equivalences for these, but this is the closest that you get:
g_path_get_basename
Note: do not get tempted by the similarly called baseName() and completeBaseName() in Qt as they are not the same. The Qt and Glib developers decided to use different terms for the same things.
Also, even this is not the same because it will not behave the same way for empty file names or those which end with a slash.
g_path_get_dirname
Note: absolutePath() or canonicalPath() will not work because they will return absolute paths, whereas the glib variant returns relative paths.
strdup
Just use
std::string
,std::array
orQByteArray
. Do not get tempted thatQString
would be the same. It simply is not because that would have the UTF overhead, too, among other things.Here is some code to print these out:
main.cpp
main.pro
Build and Run
Output