Search code examples
c++qtcopyqfile

QFile copy - static vs temporary object


Next two strings of Qt C++ code do the same stuff and without any problems to me.

QFile(source).copy(destination); 
QFile::copy(source, destination);

The question is about performance of first and second. Does code of Qt optimised inside static method and doesn't it create two objects? Which one is better and etc.


Solution

  • From Qt 5.5.1:

    bool  QFile::copy(const QString &fileName, const QString &newName)
    {
        return QFile(fileName).copy(newName);
    }
    

    Hope that give's you an idea =)