forked from qt-creator/qt-creator
Utils: Add a Process::setUtf8Codec helper function
Allows us to get rid of direct includes of <QTextCodec> in a few places. Change-Id: I9e3ec953c71f78ce31230cd299c6875696445bdc Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
@@ -1748,17 +1748,23 @@ void ChannelBuffer::handleRest()
|
||||
}
|
||||
}
|
||||
|
||||
void Process::setCodec(QTextCodec *c)
|
||||
void Process::setCodec(QTextCodec *codec)
|
||||
{
|
||||
QTC_ASSERT(c, return);
|
||||
d->m_stdOutCodec = c;
|
||||
d->m_stdErrCodec = c;
|
||||
QTC_ASSERT(codec, return);
|
||||
d->m_stdOutCodec = codec;
|
||||
d->m_stdErrCodec = codec;
|
||||
}
|
||||
|
||||
void Process::setStdOutCodec(QTextCodec *c)
|
||||
void Process::setUtf8Codec()
|
||||
{
|
||||
QTC_ASSERT(c, return);
|
||||
d->m_stdOutCodec = c;
|
||||
QTextCodec *codec = QTextCodec::codecForName("UTF-8");
|
||||
d->m_stdOutCodec = codec;
|
||||
d->m_stdErrCodec = codec;
|
||||
}
|
||||
|
||||
void Process::setUtf8StdOutCodec()
|
||||
{
|
||||
d->m_stdOutCodec = QTextCodec::codecForName("UTF-8");
|
||||
}
|
||||
|
||||
void Process::setTimeOutMessageBoxEnabled(bool v)
|
||||
|
@@ -143,8 +143,9 @@ public:
|
||||
void runBlocking(std::chrono::seconds timeout = std::chrono::seconds(10),
|
||||
EventLoopMode eventLoopMode = EventLoopMode::Off);
|
||||
|
||||
void setCodec(QTextCodec *c); // for stdOut and stdErr
|
||||
void setStdOutCodec(QTextCodec *c); // for stdOut, stdErr uses executable.processStdErrCodec()
|
||||
void setCodec(QTextCodec *codec); // for stdOut and stdErr
|
||||
void setUtf8Codec(); // for stdOut and stdErr
|
||||
void setUtf8StdOutCodec(); // for stdOut, stdErr uses executable.processStdErrCodec()
|
||||
|
||||
void setTimeOutMessageBoxEnabled(bool);
|
||||
|
||||
|
@@ -13,8 +13,6 @@
|
||||
#include <utils/qtcprocess.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QTextDecoder>
|
||||
|
||||
using namespace Tasking;
|
||||
using namespace Utils;
|
||||
|
||||
@@ -195,7 +193,7 @@ bool AbstractProcessStep::setupProcess(Process &process)
|
||||
process.setLowPriority();
|
||||
|
||||
if (buildEnvironment().hasKey("VSLANG"))
|
||||
process.setStdOutCodec(QTextCodec::codecForName("UTF-8"));
|
||||
process.setUtf8StdOutCodec();
|
||||
|
||||
process.setStdOutCallback([this](const QString &s){
|
||||
emit addOutput(s, OutputFormat::Stdout, DontAppendNewline);
|
||||
|
@@ -35,7 +35,6 @@
|
||||
#include <QLoggingCategory>
|
||||
#include <QRegularExpression>
|
||||
#include <QSettings>
|
||||
#include <QTextCodec>
|
||||
#include <QVector>
|
||||
#include <QVersionNumber>
|
||||
|
||||
@@ -260,7 +259,7 @@ static QVector<VisualStudioInstallation> detectVisualStudioFromVsWhere(const QSt
|
||||
{
|
||||
QVector<VisualStudioInstallation> installations;
|
||||
Process vsWhereProcess;
|
||||
vsWhereProcess.setCodec(QTextCodec::codecForName("UTF-8"));
|
||||
vsWhereProcess.setUtf8Codec();
|
||||
vsWhereProcess.setCommand({FilePath::fromString(vswhere),
|
||||
{"-products", "*", "-prerelease", "-legacy", "-format", "json", "-utf8"}});
|
||||
vsWhereProcess.runBlocking(5s);
|
||||
@@ -2114,7 +2113,7 @@ std::optional<QString> MsvcToolchain::generateEnvironmentSettings(const Utils::E
|
||||
CommandLine cmd(cmdPath, {"/D", "/E:ON", "/V:ON", "/c", saver.filePath().toUserOutput()});
|
||||
qCDebug(Log) << "readEnvironmentSetting: " << call << cmd.toUserOutput()
|
||||
<< " Env: " << runEnv.toStringList().size();
|
||||
run.setCodec(QTextCodec::codecForName("UTF-8"));
|
||||
run.setUtf8Codec();
|
||||
run.setCommand(cmd);
|
||||
run.runBlocking(1min);
|
||||
|
||||
|
@@ -11,8 +11,6 @@
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/qtcprocess.h>
|
||||
|
||||
#include <QtCore5Compat/QTextCodec>
|
||||
|
||||
using namespace Utils;
|
||||
|
||||
namespace Squish {
|
||||
@@ -209,7 +207,7 @@ Core::IDocument::OpenResult ObjectsMapDocument::openImpl(QString *error,
|
||||
Utils::Process objectMapReader;
|
||||
objectMapReader.setCommand({exe, {"--scriptMap", "--mode", "read",
|
||||
"--scriptedObjectMapPath", realFileName.toUserOutput()}});
|
||||
objectMapReader.setCodec(QTextCodec::codecForName("UTF-8"));
|
||||
objectMapReader.setUtf8Codec();
|
||||
objectMapReader.start();
|
||||
objectMapReader.waitForFinished();
|
||||
text = objectMapReader.cleanedStdOut().toUtf8();
|
||||
|
Reference in New Issue
Block a user