使用 Qt 5.6.0& MSVC2015 我有一个应用程序,在启动时,使用QProcess和ssh / plink / cat,将尝试读取远程服务器的主机名并捕获远程服务器上特定文件的内容。从Qt Creator(IDE)运行时,可以在调试或发布中运行。如果我在Qt Creator中从外部尝试相同的应用程序,则不会发出信号或者不调用插槽。
以下是相关的代码位:
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)
}
Wed Sep 28 15:36:06 2016调试:输出:“Lanner”
Wed Sep 28 15:36:06 2016调试:错误:“”
Wed Sep 28 15:36:06 2016 Debug:即将阅读systemInfo.xml ...
Wed Sep 28 15:36:06 2016调试:准备xml的猫...
Wed Sep 28 15:36:06 2016年调试: - &gt;开始发布...
Wed Sep 28 15:36:06 2016调试:在readSystemInfoXML()中
Wed Sep 28 15:36:06 2016年调试:readSystemInfoXML()只读:“\ n \ n \ t2.50-06-15 \ n 1.0 \ n \ tSINA \ n \ tclass IC \ n \ t提供一些东西\ n \ N“
Wed Sep 28 15:36:06 2016 Debug:after waitForFinished(6000)
Wed Sep 28 15:36:06 2016年调试:ICICIC
(xml dur中缺少标签格式化,只显示值)
现在发布......
Wed Sep 28 15:38:09 2016 Debug:output:“”
Wed Sep 28 15:38:09 2016调试:错误:“”
Wed Sep 28 15:38:09 2016 Debug:即将阅读systemInfo.xml ...
Wed Sep 28 15:38:09 2016调试:准备xml的猫...
Wed Sep 28 15:38:09 2016调试: - &gt;开始发布...
Wed Sep 28 15:38:09 2016 Debug:after waitForFinished(6000)
Wed Sep 28 15:38:09 2016调试:ICICIC
我搜索过其他可能有类似问题的人,最接近的是 Qt: some slots don't get executed in release mode
我尝试过触摸MainWindow.h,重新运行qmake并构建所有内容,没有运气。
任何建议都将不胜感激。 伊恩
答案 0 :(得分:0)
解决方案:事实证明它与ssh缓存密钥的方式有关,更具体地说,我的应用程序处理QProcess&#39;输出。