<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[QFile copy]]></title><description><![CDATA[<p dir="auto">Using Qt 4.7.1 and WinXP SP3.</p>
<p dir="auto">Debugging an issue with QFile::copy, below is the code;<br />
@<br />
bool copy(const QString&amp; src, const QString&amp; dst)<br />
{<br />
if (QFile::exists(dst))<br />
{<br />
// log dst file exists<br />
return false;<br />
}<br />
else<br />
{<br />
QFile fileHandler(src);<br />
if (!fileHandler.copy(dst))<br />
{<br />
// log src and dst path<br />
// log fileHandler.errorString() and fileHandler.error()<br />
// log QFile::exists(src) and QFile::exists(dst)<br />
return false;<br />
}<br />
}<br />
return true;<br />
}<br />
@</p>
<p dir="auto">This problem has occurred once and we have not been able to reproduce it. Here is the sequence of events;</p>
<ol>
<li>The destination file does not exists prior to copying</li>
<li>The QFile::copy method fails</li>
<li>The src and dst contain a correct file path</li>
<li>The QFile::errorstring returns "Unknown error" and QFile::error returns 0.</li>
<li>After the QFile::copy has failed, both src and dst file exists</li>
</ol>
<p dir="auto">This information is contradictory. The destination file is not present, copying fails but for some reason destination file is now present.</p>
<p dir="auto">The errorstring is not very helpful. The QIODevice::errorString() returns "Unknown error" if the internal errorstring variable is empty (QIODevice is the base class of QFile). How can QFile::copy return false with either an empty errorstring or errorstring set to "Unknown error"?</p>
<p dir="auto">One option would be that the filename variable inside QFile is empty, however the log proves that is not the case.</p>
]]></description><link>https://forum.qt.io/topic/17221/qfile-copy</link><generator>RSS for Node</generator><lastBuildDate>Sat, 09 May 2026 10:49:27 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/17221.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 01 Jun 2012 06:51:21 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to QFile copy on Fri, 01 Jun 2012 10:29:44 GMT]]></title><description><![CDATA[<p dir="auto">That is so strange - contradicting all - QFile::copy() returns false, but file is copied to the destination, which doesn't exist before copy call.</p>
<p dir="auto">I understand copy() will return false, if destination is available rather overwriting. This case will not happen in your case, since you check the existence of destination before copy() - very strange.</p>
]]></description><link>https://forum.qt.io/post/140548</link><guid isPermaLink="true">https://forum.qt.io/post/140548</guid><dc:creator><![CDATA[veeraps]]></dc:creator><pubDate>Fri, 01 Jun 2012 10:29:44 GMT</pubDate></item><item><title><![CDATA[Reply to QFile copy on Fri, 01 Jun 2012 10:06:42 GMT]]></title><description><![CDATA[<p dir="auto">Check Qt 4.8, there were some internal changes in this area.<br />
If it works in 4.8 your best option is to upgrade Qt version.</p>
]]></description><link>https://forum.qt.io/post/140544</link><guid isPermaLink="true">https://forum.qt.io/post/140544</guid><dc:creator><![CDATA[shanek]]></dc:creator><pubDate>Fri, 01 Jun 2012 10:06:42 GMT</pubDate></item><item><title><![CDATA[Reply to QFile copy on Fri, 01 Jun 2012 06:56:11 GMT]]></title><description><![CDATA[<p dir="auto">Might be a bug. But in order to report it on JIRA, you have to be able to reproduce the issue.</p>
<p dir="auto">Just a suggestion - check if <em>src</em> exists just like you check the destination. Might prevent problems later on.</p>
]]></description><link>https://forum.qt.io/post/140514</link><guid isPermaLink="true">https://forum.qt.io/post/140514</guid><dc:creator><![CDATA[sierdzio]]></dc:creator><pubDate>Fri, 01 Jun 2012 06:56:11 GMT</pubDate></item></channel></rss>