0
我有一個非常簡單的應用程序,應該使用QProcess做一些systemd控制。然後整個程序在下面。我每次運行應用程序,它具有以下抱怨:Qt QProcess抱怨QThread ::開始,線程創建錯誤
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升級到4.8.4的Qt但真的不應該打破QProcess中..我也無法找到一個bug報告。
何時在代碼中報告消息? – 2013-04-04 17:05:21
在這一行 - > controlWifi.start(「systemctl stop wiap.service」); – PhilBot 2013-04-04 17:34:12