QT QProcess 进行在windows下进行通信发送给子进程接受不到消息解决
Linux下,网上的通信很正常
这是QProcess的发送方式
process = new QProcess(this);
// 开始,处于准备状态
process->start(app, args);
// 开始运行
process->waitForStarted()
// 如果处于运行状态,
if (process->state() != QProcess::Running)
return;
process->write(message.toLocal8Bit());
在linux下,通过网上一般的方式,通过写入到标准输入里面,然后通过File输出出来,在Qt中,通过QSocketNotifier, 通过绑定信号槽,实现监听
// 通过监听stdio
QSocketNotifier(fileno(stdin), QSocketNotifier::Read, parent);
connect(this, SIGNAL(activated(int)), this, SLOT(receivedData()));
void receivedData()
{
// 存入到 ba
QByteArray ba;
while (true) {
const int c = getc(stdin);
if (c)
ba.append(char(c));
if (c == '\n')
break;
}
}
在windows下
StdIN并不能通过File监听下来,所以需要通过windows的a