0

我是一个项目的 QT,我想在 QT 上编译和运行一些 C++ 代码。我编写了以下代码来编译 C++ 文件。但我不知道如何检查程序是否正确编译。如果程序编译完成后,如何在终端中运行它?

修改后的代码:

void MainWindow::on_actionComplile_triggered()
{
    QProcess compile;
    compile.setWorkingDirectory("/home");
    compile.setReadChannel(QProcess::StandardOutput);
    compile.setProcessChannelMode(QProcess::MergedChannels);
    QTextStream out(stdout);

    compile.start("gnome-terminal");
    compile.write("ls"); //these lines do not get printed.  

    compile.waitForReadyRead();
    compile.waitForFinished(-1);

    QByteArray msg = compile.readAll();
    out << msg.data() << endl;
}
4

1 回答 1

0

我找到了解决方案:

void MainWindow::on_actionComplile_triggered()
{
    QProcess compile;
    compile.setWorkingDirectory("/home/royal");
    compile.setReadChannel(QProcess::StandardOutput);
    compile.setProcessChannelMode(QProcess::MergedChannels);
    QTextStream out(stdout);

    compile.start("g++",QStringList() << "tes.cpp" << "-o" << "test");
    compile.waitForFinished(-1);

    QByteArray msg = compile.readAllStandardOutput();
    if(msg.isEmpty())
    {
        qDebug() << "Successful";
    }
    else qDebug() << "Failed";
}
于 2013-05-16T04:42:36.300 回答