qt


Qt QProcess Complains about QThread::Start , Thread Creation Error


I have an extremely simple app that is supposed to use QProcess to do some systemd control. Then entire program is below. Every time I run the app, it complains with the following:
QThread::start: Thread creation error: Resource temporarily unavailable
I print out the max number of threads for one process with _POSIX_THREAD_THREADS_MAX and it prints 64. I can also run the QProcess command on the command line just fine with no issues. What gives?
Code:
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();
}
NOTE: I recently upgraded to Qt 4.8.4 from Qt 4.8.3 but that really shouldn't break QProcess.. I can't find a bug report for that either.
Try adding
if(!controlWifi.waitForStarted())
{
qDebug("Error starting process\n");
return;
}
just after the call to start.

Related Links

How to include lib3ds to qt project?
http server with basic autentification in qt
How to use QtSingleApplication?
QTabWidget inside a QSplitter switching very slow
QMake moc files confused by namespaces
Convert QStackedLayout to QHBoxLayout dynamically
Setting initial size of QTabWidget
QDir hangs on accessing CIFS remote folder when disconnected
Connect to a SLOT in Qt
Custom drawing of a QSlider (Qt)
Warning while building project using Qt 5.1 on OSX
Qlabel and Qtimer (need to make image blink)
Range of QVector
how to pass qobject as argument from signal to slot in qt connect
setViewportMargins() and “locked” rows and columns
Unable to connect signal to slot in another class

Categories

HOME
user-interface
automapper
mpdf
vagrant
subdomain
nsview
initialization
whmcs
celery
google-webmaster-tools
greasemonkey
hyperledger
u-boot
mailing-list
sharepoint-online
lapack
getopenfilename
mailmerge
stimulsoft
fosuserbundle
checkout
home
bluemix-mobile-services
spyder
restier
firemonkey-style
tortoisemerge
xdebug
offline-caching
region
mdns
d3.js-v4
dotcms
caesar-cipher
java-stream
elastica
sspi
task-parallel-library
oracle-bmcs
linq-to-excel
realstudio
nusoap
iptv
line-intersection
gtk#
pen
email-injection
rational-performance-test
data-management
callouts
msbuild-4.0
between
wolfram-language
maven-release-plugin
static-methods
persistent-object-store
miniconda
msgpack
ruby-on-rails-4.1
asp.net-web-api-helppages
dbmigrate
scala-macros
innerhtml
text-align
r.java-file
createfile
jolie
juttle
android-2.3-gingerbread
commenting
application-blocks
san
sunstudio
blobstorage
significant-digits
session-0-isolation
gprof
xalan
multiple-dispatch
xcode4.5
clrprofiler
trialware
mkannotation
kohana-auth
cewolf
qcar-sdk
printqueue
aptitude
ppc
xap
regioninfo

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile