Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Highlighted
Developer
Posts: 1,746
Registered: ‎04-08-2010
My Device: Passport Silver, PRIV
My Carrier: Telekom.de, O2, Vodafone

QProcess, Signals Slots, ... correct way to handle lifecycle

never used QProcess yet

 

Is this the right way to use QProcess ?

Pseudo code:

startProgram(){
    mProcess = new QProcess(this)
    connect(.....)
    // connects readyReadStandardOutput, readyReadStandardError, finished
    mProcess->start(program, arguments)
}

onFinished(int errorCode){
    // if error code != 0 report warning or so
    mProcess->deleteLater()
    // start a QTimer and then from timer:
    startprogram()
}

I expect:
* always - doesn't matter if errors are reported or not - QProcess will signal finished()
* deleteLater() from my SLOT onFinished() will remove all the connections
* so it's safe to start again with new QProcess() and new connections

from my POV there should be no hole,
but want to ask the Qt experts ;-)

-------------------------------------------------------------------------------
ekke (independent software architect, rosenheim, germany)

BlackBerry Elite Developer
BlackBerry Platinum Enterprise Partner
International Development native Mobile Business Apps
BlackBerry 10 | Qt Mobile (Android, iOS)
Workshops / Trainings / Bootcamps

blog: http://ekkes-corner.org
mobile-development: http://appbus.org Twitter: @ekkescorner
Developer
Posts: 1,746
Registered: ‎04-08-2010
My Device: Passport Silver, PRIV
My Carrier: Telekom.de, O2, Vodafone

Re: QProcess, Signals Slots, ... correct way to handle lifecycle

ping

-------------------------------------------------------------------------------
ekke (independent software architect, rosenheim, germany)

BlackBerry Elite Developer
BlackBerry Platinum Enterprise Partner
International Development native Mobile Business Apps
BlackBerry 10 | Qt Mobile (Android, iOS)
Workshops / Trainings / Bootcamps

blog: http://ekkes-corner.org
mobile-development: http://appbus.org Twitter: @ekkescorner
Developer
Posts: 77
Registered: ‎05-21-2012
My Device: DA C, Z10 LE, Passport
My Carrier: TIM

Re: QProcess, Signals Slots, ... correct way to handle lifecycle

I used to do something similar. I would start the process again only by checking the exitStatus (or errorCode) in the  onFinished() slot,  without the need of using a QTimer:

 

onFinished ( int exitCode,  exitStatus ) {
     if (exitStatus == QProcess::NormalExit) startprogram();
     if (exitStatus == QProcess::CrashExit) { ... }
}

 

If I remember well, when the process emits finished(), maybe there is still something to read in the standard output buffer that's not catched by readyReadStandard*()

Developer
Posts: 1,746
Registered: ‎04-08-2010
My Device: Passport Silver, PRIV
My Carrier: Telekom.de, O2, Vodafone

Re: QProcess, Signals Slots, ... correct way to handle lifecycle

[ Edited ]

I'm using a QTimer because I want to execute to command only every x seconds

 

and I think it's no problem if still processing standard output buffer because deleteLater will do it safely

-------------------------------------------------------------------------------
ekke (independent software architect, rosenheim, germany)

BlackBerry Elite Developer
BlackBerry Platinum Enterprise Partner
International Development native Mobile Business Apps
BlackBerry 10 | Qt Mobile (Android, iOS)
Workshops / Trainings / Bootcamps

blog: http://ekkes-corner.org
mobile-development: http://appbus.org Twitter: @ekkescorner