本质上,我拥有的是一个QtGUI应用程序,它调用 QProcess::start()
在可执行文件上重复执行,该可执行文件检查vscode扩展名写入的文本文件中的文件更改。目前有两个问题。我不认为写入文件是最有效的方法,如果是,我该如何构造可执行文件,以便它可以等待退出代码,比如 QProcess::waitForReadyRead()
但是对于文件上的当前进程?
下面是qt端用于检查文件的进程的代码:
int main(int argc_orig, char *argv_orig[])
{
QIODevice m_outputDevice;
bool reachedEnd = false;
QJsonObject jObject, breakObject;
int prev_line = -1, curr_line = prev_line;
QString fileText;
char buffer[100];
std::string file_name = Path(QDir::currentPath().toStdString()).resolve_path(".vscode").resolve_path("vscode_ael_api.json");
while (!reachedEnd)
{
while (curr_line == prev_line)
{
QFile inFile, sourceFile;
inFile.open(fopen(file_name.c_str(), "r"), QIODevice::ReadOnly);
QTextStream in(&inFile);
fileText = in.readAll();
QJsonDocument doc = QJsonDocument::fromJson(fileText.toUtf8());
jObject = doc.object();
curr_line = jObject["currentLine"].toInt();
}
//reachedEnd = jObject["reachedEnd"].toBool();
//If this isn't set to true we get errors
reachedEnd = true;
std::string curr_file = jObject["fileName"].toString().toStdString();
breakObject = jObject["breakPoints"].toObject();
prev_line = curr_line;
//Register BreakPoints
auto array = breakObject["value"].toArray();
for (const QJsonValue &v : array)
{
auto x = v[1].toArray();
for (const QJsonValue &y : x)
{
if (y.toObject()["verified"].toBool() == true)
{
//Write command breakpoints
sprintf(buffer, "C%d\t", static_cast<int>(1));
m_outputDevice->write(buffer, strlen(buffer));
}
}
}
//Write command run
sprintf(buffer, "C%d\t", static_cast<int>(0));
m_outputDevice->write(buffer, strlen(buffer));
}
return 0;
}
如果 reachedEnd
未设置为true,我得到:
“调试Assert失败”程序。。。文件:fseek.c行:100
表达式:(流!=空)
暂无答案!
目前还没有任何答案,快来回答吧!