简体   繁体   English

Popen 使 Qt 调试器崩溃

[英]Popen crashes Qt debugger

I am trying to build an app that's showing me multiple widgets about different resources on my machine.我正在尝试构建一个应用程序,向我展示有关我机器上不同资源的多个小部件。 In the code i am using popen() to run a command and get its output, to display on my widget.在代码中,我使用 popen() 来运行命令并获取其输出,以显示在我的小部件上。

However, when i try to run it in debug mode, at the first occurence of popen the debugger stops, and the app acts as if it was launched without the debugger.但是,当我尝试在调试模式下运行它时,在第一次出现 popen 时,调试器会停止,并且应用程序就像是在没有调试器的情况下启动的一样。 It doesn't close, and a part code is not being run, and i can't figure out why without the debugger.它没有关闭,并且没有运行部分代码,如果没有调试器,我无法弄清楚为什么。

I am using Qt version 5.13.2.我正在使用 Qt 版本 5.13.2。 This is an example of what makes the debugger stop.这是使调试器停止的示例。

    char s[500];
    char cmd[20]="ifconfig ";
    strcat(cmd,_currentNIC._nicName.toStdString().c_str());
    strcat(cmd," ");
    FILE* pip=popen(cmd,"r");
    fgets(s,499,pip);

In the code i am using popen() to run a command and get its output, to display on my widget.在代码中,我使用 popen() 来运行命令并获取其输出,以显示在我的小部件上。

Since widget suggest that you not only use Qt Creator as a IDE, but also yo use Qt framework, I would recommend you to use QProcess .由于widget建议您不仅使用 Qt Creator 作为 IDE,而且还使用 Qt 框架,因此我建议您使用QProcess

Qt is quite cool multi-platform framework so if you do not have to use system specific API you should avoid it. Qt 是非常酷的多平台框架,所以如果你不必使用系统特定的 API,你应该避免使用它。


Second thing is use of ifconfig . 第二件事是使用ifconfig You do not have to use command line tools to fetch such information. 您不必使用命令行工具来获取此类信息。 Qt provides API to provide such information see QNetworkInterface Qt 提供了 API 来提供这样的信息见QNetworkInterface


You can also report a bug to Qt Creator project. 您还可以向 Qt Creator 项目报告错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM