forked from qt-creator/qt-creator
Use QtcProcess in NimSuggestServer
Change-Id: If4e67a06cfb44c4ae94a78930745d29fb2330b9a Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -25,15 +25,16 @@
|
||||
|
||||
#include "server.h"
|
||||
|
||||
using namespace Utils;
|
||||
|
||||
namespace Nim {
|
||||
namespace Suggest {
|
||||
|
||||
NimSuggestServer::NimSuggestServer(QObject *parent) : QObject(parent)
|
||||
{
|
||||
connect(&m_process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
|
||||
this, &NimSuggestServer::onFinished);
|
||||
connect(&m_process, &QProcess::started, this, &NimSuggestServer::onStarted);
|
||||
connect(&m_process, &QProcess::readyReadStandardOutput, this,
|
||||
connect(&m_process, &QtcProcess::finished, this, &NimSuggestServer::onFinished);
|
||||
connect(&m_process, &QtcProcess::started, this, &NimSuggestServer::onStarted);
|
||||
connect(&m_process, &QtcProcess::readyReadStandardOutput, this,
|
||||
&NimSuggestServer::onStandardOutputAvailable);
|
||||
}
|
||||
|
||||
@@ -63,14 +64,14 @@ bool NimSuggestServer::start(const QString &executablePath,
|
||||
m_port = 0;
|
||||
m_executablePath = executablePath;
|
||||
m_projectFilePath = projectFilePath;
|
||||
m_process.start(executablePath, {"--epc", m_projectFilePath});
|
||||
m_process.setCommand({FilePath::fromString(executablePath), {"--epc", m_projectFilePath}});
|
||||
m_process.start();
|
||||
return true;
|
||||
}
|
||||
|
||||
void NimSuggestServer::kill()
|
||||
{
|
||||
disconnect(&m_process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
|
||||
this, &NimSuggestServer::onFinished);
|
||||
disconnect(&m_process, &QtcProcess::finished, this, &NimSuggestServer::onFinished);
|
||||
m_process.kill();
|
||||
m_process.waitForFinished();
|
||||
clearState();
|
||||
@@ -103,12 +104,11 @@ void NimSuggestServer::onStandardOutputAvailable()
|
||||
}
|
||||
}
|
||||
|
||||
void NimSuggestServer::onFinished(int exitCode, QProcess::ExitStatus exitStatus)
|
||||
void NimSuggestServer::onFinished()
|
||||
{
|
||||
clearState();
|
||||
|
||||
Q_UNUSED(exitCode)
|
||||
if (exitStatus == QProcess::ExitStatus::CrashExit)
|
||||
if (m_process.exitCode() == QProcess::ExitStatus::CrashExit)
|
||||
emit crashed();
|
||||
else
|
||||
emit finished();
|
||||
|
@@ -28,7 +28,8 @@
|
||||
#include <QDebug>
|
||||
#include <QFile>
|
||||
#include <QObject>
|
||||
#include <QProcess>
|
||||
|
||||
#include <utils/qtcprocess.h>
|
||||
|
||||
namespace Nim {
|
||||
namespace Suggest {
|
||||
@@ -39,38 +40,29 @@ class NimSuggestServer : public QObject
|
||||
|
||||
public:
|
||||
NimSuggestServer(QObject *parent = nullptr);
|
||||
|
||||
~NimSuggestServer();
|
||||
|
||||
bool start(const QString &executablePath, const QString &projectFilePath);
|
||||
|
||||
void kill();
|
||||
|
||||
quint16 port() const;
|
||||
|
||||
QString executablePath() const;
|
||||
|
||||
QString projectFilePath() const;
|
||||
|
||||
signals:
|
||||
void started();
|
||||
|
||||
void finished();
|
||||
|
||||
void crashed();
|
||||
|
||||
private:
|
||||
void onStarted();
|
||||
|
||||
void onStandardOutputAvailable();
|
||||
|
||||
void onFinished(int exitCode, QProcess::ExitStatus exitStatus);
|
||||
|
||||
void onFinished();
|
||||
void clearState();
|
||||
|
||||
bool m_started = false;
|
||||
bool m_portAvailable = false;
|
||||
QProcess m_process;
|
||||
Utils::QtcProcess m_process;
|
||||
quint16 m_port = 0;
|
||||
QString m_projectFilePath;
|
||||
QString m_executablePath;
|
||||
|
Reference in New Issue
Block a user