我正在打印QProcess::readAllStandardOutput()
的输出(在Ubuntu 18.04上),它可以正常工作,但是\n
字符实际上不是换行符,并以某种方式确实显示为字符串的一部分:>
/usr/local/lib/libpcl_search.so\n/usr/local/lib/libpcl_sample_consensus.so\n/usr/local/lib/libpcl_io.so\n/usr/local/lib/libpcl_segmentation.so\n/usr/local/lib/libpcl_common.so\n/usr/local/lib/libboost_random.so\n/usr/local/lib/libboost_math_tr1l.so
运行find / -name "*so"
命令并以如下所示打印QProcess时输出:
qDebug() << m_process->readAllStandardOutput();
我想这是编码问题。?
答案 0 :(得分:2)
该问题是由于QDebug将显示结尾行和类似字符而引起的,因为您正在向它们传递QByteArray,如果要查看所需的输出,请使用qPrintable:
#include <QCoreApplication>
#include <QProcess>
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QProcess process;
QObject::connect(&process, &QProcess::readyReadStandardOutput, [&process](){
qDebug()<< qPrintable(process.readAllStandardOutput());
});
process.start("find / -name \"*so\"");
return a.exec();
}
输出:
/snap/core/4917/lib/crda/libreg.so
/snap/core/4917/lib/i386-linux-gnu/ld-2.23.so
/snap/core/4917/lib/i386-linux-gnu/libBrokenLocale-2.23.so
/snap/core/4917/lib/i386-linux-gnu/libSegFault.so
/snap/core/4917/lib/i386-linux-gnu/libanl-2.23.so
/snap/core/4917/lib/i386-linux-gnu/libc-2.23.so
/snap/core/4917/lib/i386-linux-gnu/libcidn-2.23.so
...