PDA

View Full Version : App No Longer Works When Launched from Outside Creator



IanCC
29th September 2016, 14:26
Using Qt 5.6.0 & MSVC2015 I have an app which upon start-up, using QProcess and ssh/plink/cat, shall attempt to read the hostname of a remote server and capture the contents of a specific file on a remote server. This works when run from Qt Creator (the IDE), in either debug or release. If I attempt the same app from outside if Qt Creator, either the signal is never emitted or the slot is not called.



void MainWindow::Perform1stSSHcmd()
{
QPalette palette;
// hostname: THIS IS OUR 1st SSH COMMAND SO WE WANT TO DETERMINE IF THE KEYS ARE SET UP OK...
QProcess* qp = new QProcess( this );
QString userAndCommand = "root@";
userAndCommand.append( m_cmsIp );
userAndCommand.append(" hostname"); // cmd we want to execute on the remote server

qp->start( m_plinkPuttyCmd.arg( userAndCommand ));
qp->waitForFinished( 16000 ); // I've tried vaious values for this
QString output = qp->readAll();
QString err = qp->readAllStandardError();
// ... SNIP various error checking here ...

// Now the system info
m_sysInfoProc = new QProcess(this);

qDebug() << "About to read systemInfo.xml... ";
if( !connect( this->m_sysInfoProc, SIGNAL( readyReadStandardOutput() ), SLOT( readSystemInfoXML() ))) {
qDebug() << "Connect Failed!!!!!";
}
userAndCommand = "root@";
userAndCommand.append( m_cmsIp );
qDebug() << "preparing cat of xml... ";
userAndCommand.append(" cat /root/systemInfo.xml");
m_sysInfoProc->start( m_plinkPuttyCmd.arg( userAndCommand ));

qDebug() << "->start issued... ";
m_sysInfoProc->waitForFinished( 6000 );
qDebug() << "after waitForFinished( 6000 )";
}


void MainWindow::readSystemInfoXML()
{
qDebug() << "In readSystemInfoXML()";

QProcess *systemInfoXml = qobject_cast<QProcess *>(sender());
if( !systemInfoXml ) {
return;
}

QString res = systemInfoXml->readAllStandardOutput();
qDebug() << "readSystemInfoXML() just read:" << res;
if( !res.length() ) {
return;
}
// . . . XML parsing of file contents . . . (not a concern, works fine)
}



Output Debug/Releas Mode from IDE:

==================================
Wed Sep 28 15:36:06 2016 Debug: output: "Lanner\n"
Wed Sep 28 15:36:06 2016 Debug: err: ""
Wed Sep 28 15:36:06 2016 Debug: About to read systemInfo.xml...
Wed Sep 28 15:36:06 2016 Debug: preparing cat of xml...
Wed Sep 28 15:36:06 2016 Debug: ->start issued...
Wed Sep 28 15:36:06 2016 Debug: In readSystemInfoXML()
Wed Sep 28 15:36:06 2016 Debug: readSystemInfoXML() just read: "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<system> \n\t<swRev>2.50-06-15</swRev>\n <hwRev>1.0</hwRev>\n \t<ident>SINA</ident>\n \t<class>class IC</class>\n \t<description>does something</description>\n </system>\n"
Wed Sep 28 15:36:06 2016 Debug: after waitForFinished( 6000 )
Wed Sep 28 15:36:06 2016 Debug: ICICIC

Output when started from release folder on my Windows box:
================================================== ========
Wed Sep 28 15:38:09 2016 Debug: output: ""
Wed Sep 28 15:38:09 2016 Debug: err: ""
Wed Sep 28 15:38:09 2016 Debug: About to read systemInfo.xml...
Wed Sep 28 15:38:09 2016 Debug: preparing cat of xml...
Wed Sep 28 15:38:09 2016 Debug: ->start issued...
Wed Sep 28 15:38:09 2016 Debug: after waitForFinished( 6000 )
Wed Sep 28 15:38:09 2016 Debug: ICICIC

I've tried clean builds and running qmake (over and over) as well as reverting back to Qt 5.5.1 (VS2013) without any luck.

This used to work fine, I've no idea what might of changed. Any thoughts would be greatly appreciated.
Ian

anda_skoa
29th September 2016, 18:13
Aside from the usually bad idea to put the arguments of a command into the command string (better use command + list of arguments), this sounds like an environment issue.

E.g. mabye something is present in the environment of QtCreator but not when run stand alone.

I assume in both case you are running this with the same user account?

Cheers,
_

IanCC
29th September 2016, 21:21
Anda,

Thanks for your reply and you are right, it was environment related. It turns out that I had an new IP which my ssh cache didn't know about. From the cmd line it was obvious, but from my Qt app, its qProcess was missing the correct string comparison for the 'do you want to cache this unknown key;. I thought that it would show up in the debug output, but I missed it.

Thanks to Anda and everyone who read. :)

Cheers,
Ian