我有一个非常简单的应用程序,应该使用QProcess来进行一些系统控制。然后整个程序在下面。每次我运行应用程序时,都会抱怨以下内容:
QThread::start: Thread creation error: Resource temporarily unavailable
我使用_POSIX_THREAD_THREADS_MAX打印出一个进程的最大线程数,并打印64.我也可以在命令行上运行QProcess命令,没有问题。是什么给了什么?
代码:
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
// Get the command line parameter to turn wifi on or off
QString wifiSwitch = argv[1];
// Print the number of threads available
qDebug() << "Single Process can spawn this many threads:" << _POSIX_THREAD_THREADS_MAX;
// Switch based on the input and control wifi with systemctl
if ( wifiSwitch == "on" ) {
// Subprocess systemd
QProcess controlWifi;
controlWifi.start("systemctl start wiap.service");
controlWifi.waitForFinished();
// Grab the output and use it to determine whether we successfully turned on the wifi
QString didTurnOnWifi = QString(controlWifi.readAll()).trimmed();
controlWifi.close();
// So if there is no error messages from the subprocess we were successful
if ( didTurnOnWifi.length() == 0 ) {
qDebug() << "SUCCESS";
exit(0);
}
else {
qDebug() << "FAILURE";
exit(-1);
}
}
else if ( wifiSwitch == "off" ) {
// Subprocess systemd
QProcess controlWifi;
controlWifi.start("systemctl stop wiap.service");
controlWifi.waitForFinished();
// Grab the output and use it to determine whether we successfully turned on the wifi
QString didTurnOnWifi = QString(controlWifi.readAll()).trimmed();
controlWifi.close();
// So if there is no error messages from the subprocess we were successful
if ( didTurnOnWifi.length() == 0 ) {
qDebug() << "SUCCESS";
}
else {
qDebug() << "FAILURE";
}
}
else {
// No arguments
qDebug() << "FAILURE: You didn't specify any command line arguments, call this program like './fluke-control-wifi on|of'";
exit(-1);
}
return a.exec();
}
注意:我最近从Qt 4.8.3升级到Qt 4.8.4但是真的不应该破坏QProcess ..我也找不到错误报告。
答案 0 :(得分:0)
尝试添加
if(!controlWifi.waitForStarted())
{
qDebug("Error starting process\n");
return;
}
刚开始致电之后。