C++ Qt5 QDir rename returning false

I am new to Qt and learning about renaming files with the QDir and QFile libraries.

I know how to rename and I can do it but when I try in this loop it does not work.

QDir editFile;
std::cout << "Attempting to chop and put .mp4 onto a regular file.\n";
QString fileNameBuf{argv};
QString fileOriginal{argv};
for(int l{0}; l < fileNameBuf.size(); ++l)
    if(fileNameBuf.at(l) == '.')
        fileNameBuf.chop(fileNameBuf.size() - l);
if(editFile.rename(argv, fileNameBuf))
    std::cout << "Successful\n";
    std::cout << "did not make it.\n";

This is actually in a function that sends a QString named argv. argv is a file path. I have it append .mp4 and remove the old extension. I have heard and know that if you do Q rename wrong it will not work. Please help me with this code. I have looked at other posts about this but they do not seem to help.

I hope you are aware that files don't work like that... just changing the extension of a file doesn't mean it result into a new valid file type.

having said that. No need to reinvent the wheel:

check the official doc:


QFile editFile{"foo.txt"};
std::cout << "Attempting to chop and put .mp4 onto a regular file.\n";
    std::cout << "Successful\n";
    std::cout << "did not make it.\n";

C Programming Tutorial for Beginners, Learn C the Hard Way: Practical Exercises on the Computational Subjects You Keep Avoiding (Like C) C is a successor of B language which was introduced around the early 1970s. The language was formalized in 1988 by the American National Standard Institute (ANSI). The UNIX OS was totally written in C. Today C is the most widely used and popular System Programming Language. Most of the state-of-the-art software have been implemented using C.

Why use for () for this task if Qt has indexOf () to find a character in the string?

Why not use replace () to change the file extension?

QString::replace does this task easily, because if the string does not contain the source string, it will do nothing...

"C" Programming Language: Brian Kernighan, This course will give you a full introduction into all of the core concepts in the C programming Duration: 3:46:13 Posted: Aug 15, 2018 C is a compiled language. Because the ideas behind C are kept close to the design of the computer, the compiler (program builder) can generate machine code/native code for the computer. Programs built in machine code are very fast. This makes C a good language for writing operating systems.

Like said previously, use Qt's functions. Make sure that if you have this problem that you are not opening the file before renaming it. That was what I was doing wrong here which of corse unless you close it or the file goes out of scope you wont be able to rename it. Thanks for the insights all those who replied.

Why C is so Influential - Computerphile, "C" is one of the most widely used programming languages of all time. Prof Brian Kernighan Duration: 8:26 Posted: Aug 18, 2015 C is a procedural programming language. It was initially developed by Dennis Ritchie as a system programming language to write operating system. The main features of C language include low-level access to memory, simple set of keywords, and clean style, these features make C language suitable for

How easy is it to learn C?, Why is C such an influential language? We asked ardent C fan Professor Brailsford. Brian Duration: 10:50 Posted: Aug 25, 2017 Discover historical prices for C stock on Yahoo Finance. View daily, weekly or monthly format back to when Citigroup, Inc. stock was issued.

How is C programming language still used today?, - and extremely flexible. So flexible, in fact, that as you use the language, you probably go through many different programming styles as you work out how to use the language to produce good, maintainable, reliable code. Hello World using C++. Just to give you a little excitement about C++ programming, I'm going to give you a small conventional C++ Hello World program, You can try it using Demo link. C++ is a super set of C programming with additional implementation of object-oriented concepts.

Which programs are written in C language?, is best choice when you start programming as it is most basic. Microsoft C++, C, and Assembler documentation. Learn how to use C++, C, and assembly language to develop applications, services, and tools for your platforms and devices.