PDA

View Full Version : multiple process ID while QProcess start() function



arunanncyda
26th November 2014, 06:06
Hi

Im my program, activating the the GPRS using Qprocess start function, while executing this program will activate the GPRS. But the application is creating two more process PID with same application name & that two process will not be terminating. kindly help me how to solve this problem.


void GPRSCall::activateGPRS() {
QProcess *activateProcess;
activateProcess = new QProcess();
connect(activateProcess,SIGNAL(readyReadStandardOu tput()),this,SLOT(readGPRS()));
activateProcess->start("pppd call gprs-airtel",QIODevice::ReadOnly);
}

void GPRSCall::readGPRS()
{
str = activateProcess->readAllStandardOutput();
qDebug() << str;
if(str.contains("local IP address")) {
QString ipAddress=getip("ppp0");
emit gprsResponse(tr("GPRS Activated Successfully<br>IP : ")+ipAddress);
activateProcess->disconnect(activateProcess,SIGNAL(readyReadStandar dOutput()),this,SLOT(readGPRS()));
} else if(str.contains("script failed") || str.contains("Serial link disconnected")) {
emit gprsResponse(tr("GPRS Activation Failed"));
activateProcess->disconnect(activateProcess,SIGNAL(readyReadStandar dOutput()),this,SLOT(readGPRS()));
} else if(str.contains("ttyUSB0 is locked")) {
emit gprsResponse(tr("GPRS Activation Failed"));
}
else if(str.contains("Modem hangup")) {
emit gprsResponse(tr("Modem Hangup"));
activateProcess->disconnect(activateProcess,SIGNAL(readyReadStandar dOutput()),this,SLOT(readGPRS()));
}
}

/*Obtains the IP Address from the conncted network interrface*/
QString GPRSCall::getip(QString dev)
{
QNetworkInterface iface = QNetworkInterface::interfaceFromName(dev);
QList<QNetworkAddressEntry> ipList = iface.addressEntries();
for (int i = 0; i < ipList.size(); ++i)
return ipList.at(i).ip().toString();
return "No Link";
}


/********************GPRS Deactivation********************/
/*GPRS Disconnect Script is called from a process in ReadOnly Mode*/
void GPRSCall::deactivateGPRS()
{
connect(deactivateProcess,SIGNAL(readyReadStandard Output()),this,SLOT(closeGPRS()));
deactivateProcess->start("sh /opt/Resources/gprs_disconnect.sh",QIODevice::ReadOnly);
delay(1);///add Stopping PPP interface to readyreadstandarouuput method...
}

/***************Read Deactivation Script Output***************/
/*Invoked form Disconnect Script to read its output and display
the status to the user*/
void GPRSCall::closeGPRS()
{
str = deactivateProcess->readAllStandardOutput();
if(str.contains("Stopping PPP interface ")) {
emit gprsResponse(tr("GPRS Deactivation Success"));
deactivateProcess->disconnect(deactivateProcess,SIGNAL(readyReadStand ardOutput()),this,SLOT(closeGPRS()));
}
}

Note : USing QT 4.8.1 version & Linux 2.6.36.4 armv5tejl GNU/Linux

anda_skoa
26th November 2014, 09:23
That should actually crash.

activateGPRS() is storing the QProcess pointer in a local variable, readGPRS() is accessing a member variable.

Cheers,
_

arunanncyda
28th November 2014, 06:53
Hi,
Thank for your reply, I extended scope of QProcess by declaring it in header file. Now also I am getting same problem.

QT Code
void GPRSCall::activateGPRS() {
// QProcess *activateProcess; // Moved to Header file
// activateProcess = new QProcess(); // Moved to constructor.
connect(activateProcess,SIGNAL(readyReadStandardOu tput()),this,SLOT(readGPRS()));
activateProcess->start("pppd call gprs-airtel",QIODevice::ReadOnly);
}

arunanncyda
4th December 2014, 09:42
Hi,
Thank for your reply, I extended scope of QProcess by declaring it in header file. Now also I am getting same problem.

QT Code
void GPRSCall::activateGPRS() {
// QProcess *activateProcess; // Moved to Header file
// activateProcess = new QProcess(); // Moved to constructor.
connect(activateProcess,SIGNAL(readyReadStandardOu tput()),this,SLOT(readGPRS()));
activateProcess->start("pppd call gprs-airtel",QIODevice::ReadOnly);
}

^NyAw^
4th December 2014, 10:32
Hi,

Use a debugger and check how many times "activateGPRS()" is called.