QFile(1) - 几个静态函数

    技术2024-06-27  66

    QFile类的一些静态函数     1    bool QFile::exists ( const QString & fileName ) [static]     2    bool QFile::rename ( const QString & oldName, const QString & newName ) [static]     3    bool QFile::copy ( const QString & fileName, const QString & newName ) [static]     4    bool QFile::remove ( const QString & fileName ) [static]        5    bool QFile::link ( const QString & fileName, const QString & linkName ) [static]     6    QString QFile::symLinkTarget ( const QString & fileName ) [static]         Permissions QFile::permissions ( const QString & fileName ) [static]     void QFile::setDecodingFunction ( DecoderFn function ) [static]     void QFile::setEncodingFunction ( EncoderFn function ) [static]         这次先试下前6个,后面3个暂时pass     详细帮助请看官方帮助文档。     例1     包含文件         main.cpp     说明         很简单的函数调用,具体见注释         代码                  //main.cpp #include <QtCore/QCoreApplication> #include <QFile> #include <QDebug> int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); QString path = "/other/test/gw"; QString path2 = "/other/test/yue"; QString path3 = "/other/test/link"; //判断文件是否存在 qDebug() << "task1:/t" << QFile::exists(path); //将文件重命名 qDebug() << "task2:/t" << QFile::rename(path,path2); //拷贝文件 qDebug() << "task3:/t" << QFile::copy(path2,path); //删除文件 qDebug() << "task4:/t" << QFile::remove(path2); //创建快捷方式 qDebug() << "task5:/t" << QFile::link(path,path3); //得到快捷方式的目标文件 qDebug() << "task6:/t" << QFile::symLinkTarget(path3); //删除快捷方式 qDebug() << "task7:/t" << QFile::remove(path3); return app.exec(); } 

    最新回复(0)