需求
在实际Qt开发中,经常遇到对 用户通过DialogTree指定的文件 进行移动操作,即copy()方法,将绝对路径下的文件复制到其他路径下。
方法
主要利用:
QDir::currentPath() //返回应用程序目录的当前绝对路径,
//The current directory is the last directory set with
//QDir::setCurrent() or, if that was never called, the directory at
//which this application was started at by the parent process.
QFile f(absolutepath); //通过用户定义的绝对路径定义一个QFile对象,
QString &QString::append(const QString &str)
//在字符串后添加字符串,可以用来改变绝对地址。
实例1
获取应用程序目录的绝对路径;
删除该绝对路径下的123.txt;
重命名1234.txt为12345.txt;
复制12345.txt为123456.txt;
#include <QDir>
#include <QString>