Home > Software engineering >  QT Debugging QFile::remove() Windows 10 MSVS 2019
QT Debugging QFile::remove() Windows 10 MSVS 2019

Time:04-03

I am working on a QT application that has to communicate with a few Windows-utilities. The result of these utilities are a couple of “production-files” that should be listed in a “filenames-txt-file” for further use.

The production of such a “filenames-txt-file” with the list of “production-files” is done with QT using QFileInfo.
Sometimes an old “filenames-txt-file” already exists in the working-directory and should be removed before it can be created with the new results.

Here is the problem:
QFile::remove("somefile") does not work while debugging.
It works fine, when I run the Exe in the debug-folder outside MSVS,
and it works fine running the release version.

While debugging, I get this messages:

if (QFile::exists(filenameFull)) {
    QFile f (filenameFull);     
    qDebug() << f.remove(filenameFull);     // returns false
    qDebug() << f.errorString();            // returns “unknown error”
}

I elevated Microsoft Visual Studio 2019 to run as administrator.
I did set the UAC execution level to “highestAvailable”.
Is anything else needed to make this code working while debugging?

CodePudding user response:

It may be unrelated but instead f.remove(filenameFull) you can just use f.remove() or QFile::remove(filenameFull).

QFile::remove on windows uses winapi function DeleteFileW(("\\\\?\\" QDir::toNativeSeparators(filenameFull)).utf16()) where "\\?\" is used to avoid MAX_PATH limitation. Try calling this function directly and analyze result.

CodePudding user response:

You are calling static function, QFile::remove(QString filename), so f does not see the error. So try this:

if (QFile::exists(filenameFull)) {
    QFile f (filenameFull);
    qDebug() << f.exists();
    qDebug() << f.remove();      
    qDebug() << f.errorString();
}

That should solve the part about not getting error string.

  • Related