QT 调试 QFile::remove() Windows 10 MSVS 2019
我正在研究一个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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
它可能是无关的,而是
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 usef.remove()
orQFile::remove(filenameFull)
.QFile::remove
on windows uses winapi functionDeleteFileW(("\\\\?\\" + QDir::toNativeSeparators(filenameFull)).utf16())
where "\\?\" is used to avoid MAX_PATH limitation. Try calling this function directly and analyze result.您正在调用静态函数
QFile::remove(QString filename)
,因此f
看不到错误。所以试试这个:这应该可以解决有关未获取错误字符串的部分。
You are calling static function,
QFile::remove(QString filename)
, sof
does not see the error. So try this:That should solve the part about not getting error string.
感谢@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.