Qt-qurinfo使用示例
我看到Qt有一个漂亮的类名qurinfo。它有我想使用的方法/函数,但我不知道如何使用这个类。初始化看起来非常奇怪和笨拙。 例如: 我想使用它名为qurInfo::setLastModified的方法,以便为本地文件设置lastModified时间戳。(也在共享netw文件上,但现在我只想关注本地文件) 假设本地文件是“D:/dir1/dir2/file.txt” 当我只有项目的完整文件名(“D:/dir1/dir2/file.txt”)并且希望使用QUrlInfo的GET和SET方法时,如何使用QUrlInfo?我特别想举一个例子,说明如何创建一个qurinfo对象并使用它的qurinfo::setLastModified方法 更深入的解释: 我感到困惑的主要原因是它的构造函数看起来像 跟随Qt-qurinfo使用示例,qt,qt4,Qt,Qt4,我看到Qt有一个漂亮的类名qurinfo。它有我想使用的方法/函数,但我不知道如何使用这个类。初始化看起来非常奇怪和笨拙。 例如: 我想使用它名为qurInfo::setLastModified的方法,以便为本地文件设置lastModified时间戳。(也在共享netw文件上,但现在我只想关注本地文件) 假设本地文件是“D:/dir1/dir2/file.txt” 当我只有项目的完整文件名(“D:/dir1/dir2/file.txt”)并且希望使用QUrlInfo的GET和SET方法时,如何
//Version 1: Problem is you must already have a QUrlInfo object.
QUrlInfo ( const QUrlInfo & ui )
//Version2: Problem is you must already know everything about the file.
//This makes QUrlInfo objects large set of GET methods useless for the most part
//since you must already know all the GET info prior to making a QUrlInfo object.
//Chicken and egg scenario. I don't see what is point of making a class that gets
//info... but... you must already know all that info to begin with or you can't
// initialize the the class.
QUrlInfo ( const QString & name, int permissions, const QString & owner,
const QString & group, qint64 size, const QDateTime & lastModified,
const QDateTime & lastRead, bool isDir, bool isFile, bool isSymLink,
bool isWritable, bool isReadable, bool isExecutable )
//Version3: Same problem as in version 2.
QUrlInfo ( const QUrl & url, int permissions, const QString & owner,
const QString & group, qint64 size, const QDateTime & lastModified,
const QDateTime & lastRead, bool isDir, bool isFile, bool isSymLink,
bool isWritable, bool isReadable, bool isExecutable )
从文件中
请注意,设置值不会影响qurinfo提供信息的基础资源;例如,如果在只读资源上调用setWritable(true),则唯一更改的是QUrlInfo对象,而不是资源
此类仅用于管理您已经知道的有关资源的信息
可以使用QFile
设置一些属性,但这些属性是有限的,并且在文档中会出现警告,因为行为依赖于操作系统。您可能需要使用本机API来可靠地操作文件属性