#include "pm3process.h" PM3Process::PM3Process(QThread* thread, QObject* parent): QProcess(parent) { moveToThread(thread); setProcessChannelMode(PM3Process::MergedChannels); isRequiringOutput=false; requiredOutput=new QString(); serialListener=new QTimer(); // if using new QTimer(this), the debug output will show "Cannot create children for a parent that is in a different thread." serialListener->moveToThread(this->thread());// I've tried many ways to creat a QTimer instance, but all of the instances are in the main thread(UI thread), so I have to move it manually serialListener->setInterval(1000); serialListener->setTimerType(Qt::VeryCoarseTimer); connect(serialListener,&QTimer::timeout,this,&PM3Process::onTimeout); } void PM3Process::connectPM3(const QString path, const QString port) { setRequiringOutput(true); // using "-f" option to make the client output flushed after every print. start(path, QStringList()<clear(); } QByteArray PM3Process::readLine(qint64 maxlen) { QByteArray buff; buff=QProcess::readLine(maxlen); if(isRequiringOutput) requiredOutput->append(buff); return buff; } QString PM3Process::getRequiredOutput() { return *requiredOutput; } bool PM3Process::waitForReadyRead(int msecs) { return QProcess::waitForReadyRead(msecs); } void PM3Process::setSerialListener(const QString& name,bool state) { if(state) { portInfo=new QSerialPortInfo(name); serialListener->start(); qDebug()<thread(); } else { serialListener->stop(); delete portInfo; } } void PM3Process::onTimeout() //when the proxmark3 client is unexpectedly terminated or the PM3 hardware is removed, the isBusy() will return false(tested on Windows); { qDebug()<isBusy(); if(!portInfo->isBusy()) { kill(); emit PM3StatedChanged(false); setSerialListener("",false); } } void PM3Process::testThread() { qDebug()<<"PM3:"<Raw_outputEdit->insertPlainText(btay); // btay = pm3->readLine(); // } // ui->Raw_outputEdit->moveCursor(QTextCursor::End); }