QT 调试 QFile::remove() Windows 10 MSVS 2019

发布于 2025-01-18 08:28:41 字数 655 浏览 5 评论 0原文

我正在研究一个QT应用程序,该应用程序必须与一些Windows-lities进行通信。 这些公用事业的结果是几个“生产文件”,应在“文件名-TXT文件”中列出以供进一步使用。


使用QfileInfo QT完成了这样的“文件名-TXT文件”的生产。
有时,在工作目录中已经存在一个旧的“文件名-TXT文件”,应在使用新结果创建之前将其删除。

这是一个问题:
qfile :: remove(“ somefile”)在调试时不起作用。
它可以正常工作,当我在MSV外的调试器中运行EXE时,
可以正常工作运行发行版。

在调试时,我会收到此消息:

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

我将Microsoft Visual Studio 2019提升为管理员。
我确实将UAC执行级设置为“最高可用”。
调试时是否需要其他任何内容才能使此代码工作?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

横笛休吹塞上声 2025-01-25 08:28:41

它可能是无关的,而是f.remove(filenamefull)您可以只使用f.remove() qfile :: emover :: recome remove(filenamefull) 。

qfile :: remove在Windows上使用Winapi函数deletefilew((“ \\\\?\\” + qdir :: TonativeEparators(filenamefull)).utf16())在哪里“ \\?\”用于避免MAX_PATH限制。尝试直接调用此功能并分析结果。

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.

蹲墙角沉默 2025-01-25 08:28:41

您正在调用静态函数 QFile::remove(QString filename),因此 f 看不到错误。所以试试这个:

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

这应该可以解决有关未获取错误字符串的部分。

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.

坐在坟头思考人生 2025-01-25 08:28:41

感谢@hyde 解决了。
问题确实是 filenameFull 一直被打开。
不是在代码本身,而是在配置属性 -> 中调试->命令参数
它从编码过程的早期阶段就挂在那里。
它还解释了为什么在调试过程之外运行 EXE 运行良好。
教训:始终保持我的编码步骤清晰......
谢谢你让我重回正轨。

Solved thanks to @hyde.
The issue was indeed that filenameFull was opened all the time.
Not in the code itself, but in the Configuration Properties -> Debugging -> Command Arguments
It was hanging there from an earlier stage in the coding process.
It explains as well why running the EXE outside the debugging-process was running fine.
Lesson: keep my coding steps clear at all times....
Thanks for getting me back on track.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文