【发布时间】:2017-02-06 23:54:26
【问题描述】:
使用 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)
}
从 IDE 输出调试/发布模式:
2016 年 9 月 28 日星期三 15:36:06 调试:输出:“Lanner”
2016 年 9 月 28 日星期三 15:36:06 调试:错误:“”
2016 年 9 月 28 日星期三 15:36:06 调试:即将读取 systemInfo.xml...
2016 年 9 月 28 日星期三 15:36:06 调试:准备 xml 的猫...
2016 年 9 月 28 日星期三 15:36:06 调试:->开始发布...
2016 年 9 月 28 日星期三 15:36:06 调试:在 readSystemInfoXML()
2016 年 9 月 28 日星期三 15:36:06 调试:readSystemInfoXML() 刚刚读取:“\n \n\t2.50-06-15\n 1.0\n \tSINA\n \tclass IC\n \tdoes something\n \ n"
2016 年 9 月 28 日星期三 15:36:06 调试:waitForFinished(6000)
2016 年 9 月 28 日星期三 15:36:06 调试:ICICIC
(格式化时 xml 中缺少标签,只显示值)
现在发布...
从我的 Windows 机器上的发布文件夹启动时的输出:
2016 年 9 月 28 日星期三 15:38:09 调试:输出:“”
2016 年 9 月 28 日星期三 15:38:09 调试:错误:“”
2016 年 9 月 28 日星期三 15:38:09 调试:即将读取 systemInfo.xml...
2016 年 9 月 28 日星期三 15:38:09 调试:准备 xml 的猫...
2016 年 9 月 28 日星期三 15:38:09 调试:->开始发布...
2016 年 9 月 28 日星期三 15:38:09 调试:waitForFinished(6000)
2016 年 9 月 28 日星期三 15:38:09 调试:ICICIC
我已经搜索过可能有类似问题的其他人,最接近的是 Qt: some slots don't get executed in release mode
我尝试过触摸 MainWindow.h,重新运行 qmake 并全部构建,但没有运气。
任何建议将不胜感激。 伊恩
【问题讨论】:
-
您似乎没有对
m_sysInfoProc执行任何错误/状态检查。 -
为什么要问我们问题出在哪里?您拥有找出问题所在所需的所有信息。你只是不看它......当你假装一切都成功了。
标签: qt signals release qprocess slot