如何将文件移动到Qt中的另一个现有目录 [英] How to move a file to another existing directory in Qt
问题描述
我是Qt的初学者,我的项目的一部分正在将现有文件移动到另一个现有目录中?有人可以给我一个具体的例子吗?我不确定是否应该使用Qfile :: rename().我尝试这样写
I am a beginner in Qt, one part of my project is moving a existing file to another existing directory? Can someone gives me a specific example? I am not sure whether I should use Qfile::rename(). I try write like this
QDir::rename("/home/joshua/test.txt","/home/joshua/test/test_c.txt");
但错误是无法在没有对象的情况下调用成员函数'bool QDir :: rename(const QString& ;, const QString&)' QDir :: rename("/home/joshua/test.txt","/home/joshua/test/test_c.txt"); ^
but the error is cannot call member function 'bool QDir::rename(const QString&, const QString&)' without object QDir::rename("/home/joshua/test.txt","/home/joshua/test/test_c.txt"); ^
对不起,大家都是我的错,我问了一个如此不清楚和愚蠢的问题,很抱歉浪费您的时间,我是一个初学者,在问这个问题之前,我真的没有注意到这个问题之前有人问过,因为我的水平太低了.因为我太天真了,我再也不能问问题了,所以请原谅我问这个问题,我太压力了,因为我在一家公司实习,对我来说我的项目很难,所以我别无选择.最后,我想对那些以前看过我的问题的人表示感谢.
Sorry guys, all are my wrong, I asked a so unclear and so stupid question, I am so sorry for wasting your time, I am a beginner, before I asked this question, I really really had not noticed that this question have been asked before, because my level is to low. Because I am too naive, I can not ask question anymore, so please, please forgive me asked this question, I am too stress because I internship at a company, my project for me is quite hard so that I have no choice to do such a wasting your time thing, lastly, I want to say thank you for those who had seen my questions before.
推荐答案
根据文档:
布尔QFile :: rename(const QString& newName)
将fileName()当前指定的文件重命名为newName.退货 成功则为true;否则返回false.
Renames the file currently specified by fileName() to newName. Returns true if successful; otherwise returns false.
对于您而言,您必须执行以下操作:
In your case you must do the following:
QFile file("/home/joshua/test.txt");
file.rename("/home/joshua/test/test_c.txt");
这篇关于如何将文件移动到Qt中的另一个现有目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!