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