I am porting an application from Glib to Qt.
I do have a lot of API specific to Gtk, but it's difficult to find the equivalent variants in Qt. I am looking for the alternative of these:
- g_path_get_basename
- g_path_get_dirname
- strdup
Any idea?
I am porting an application from Glib to Qt.
I do have a lot of API specific to Gtk, but it's difficult to find the equivalent variants in Qt. I am looking for the alternative of these:
Any idea?
Copyright © 2021 Jogjafile Inc.
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::arrayorQByteArray. Do not get tempted thatQStringwould 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