This commit is contained in:
curtis 2024-11-26 16:24:50 +08:00
parent 2ea5d0b7eb
commit caa9a4f9df
2 changed files with 108 additions and 0 deletions

View File

@ -0,0 +1,68 @@
#include "BCIManager.h"
#include <QFile>
#include <QApplication>
#include <QDebug>
BCIManager::BCIManager(QObject *parent)
: QObject{parent}
{
}
bool BCIManager::startLinkerPrograme()
{
QString strPath = QApplication::applicationDirPath().append("/cmd.txt");
QFile file(strPath);
if (!file.open(QIODevice::ReadOnly))
{
qDebug() << file.errorString();
return false;
}
QString strContent;
QTextStream in(&file);
while (!in.atEnd())
{
strContent = in.readLine();
if(!strContent.isEmpty())
{
break;
}
}
if(strContent.isEmpty())
{
qDebug() << "cmd is empty";
return false;
}
//启动进程
//QString strCmd = QApplication::applicationDirPath().append("/BCILinker/SunnyLinkTool/") + strContent;
QString strCmd = QString("./") + strContent;
qDebug() << strCmd;
if(nullptr == m_pCmd)
{
m_pCmd = new QProcess(this);
connect(m_pCmd, &QProcess::readyReadStandardOutput, this, &BCIManager::slotLinkerProgrameReadyReadStandardOutput);
connect(m_pCmd, &QProcess::readyReadStandardError, this, &BCIManager::slotLinkerProgrameReadyReadStandardError);
}
m_pCmd->start(strCmd);
}
void BCIManager::slotLinkerProgrameReadyReadStandardOutput()
{
if(m_pCmd)
{
qDebug() << m_pCmd->readAllStandardOutput();
}
}
void BCIManager::slotLinkerProgrameReadyReadStandardError()
{
if(m_pCmd)
{
qDebug() << m_pCmd->readAllStandardError();
}
}

View File

@ -0,0 +1,40 @@
#ifndef BCIMANAGER_H
#define BCIMANAGER_H
#include <QObject>
#include <QProcess>
#include "QmlTcpSocket/TcpSocket.h"
class BCIManager : public QObject
{
Q_OBJECT
public:
explicit BCIManager(QObject *parent = nullptr);
static BCIManager &getInstance()
{
static BCIManager instance;
return instance;
}
static void registerQMLType()
{
qmlRegisterType<QMLTcpSockets::TcpSocket>("TcpSocket", 2, 0, "TcpSocket");
}
//启动Linker工具
bool startLinkerPrograme();
private slots:
//Linker程序的标准输出
void slotLinkerProgrameReadyReadStandardOutput();
//Linker程序的错误输出
void slotLinkerProgrameReadyReadStandardError();
signals:
private:
QProcess *m_pCmd = nullptr;
};
#endif // BCIMANAGER_H