简体   繁体   中英

Unexpected behaviour of isRelative()

I am using C++ Qt Library and i was filtering out the relative paths in my file, while debugging few strings other than relative paths are also considered as relative paths. I want to know the reason of this behavior of isRelative() or i am doing something incorrectly, following example is giving true.

QFileInfo fi("1");
qDebug() << fi.isRelative();

I am reading from a file, where only few entries are relative paths, so instead of returning true for only those entries, isRelative() is returning true for many values like: "1", "0.0", "NO", etc

To make it not be relative you should specify the full path of where should it be searched (absolute path):

QFileInfo fi("/home/user/1");
qDebug() << fi.isRelative();

then it will not be relative.

In your case it is equivalent of:

QFileInfo fi("./1");
qDebug() << fi.isRelative();

Reading: Absolute path vs relative path

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM