vendredi 5 juin 2020

How to convert a QEnum to a QString and visualize it on QTextEdit [duplicate]

Given the following sample code for which I am successfully outputting the exitStatus of a QProcess::ExitStatus, I am trying to pass that string, which is also visible in the print screen below, into a QTextEdit. I am close but something is missing and cannot visualize the string QProcess::ExitStatus(Normal) into my QTextEdit:

meta

void MainWindow::startLidar()
{
    // Execution of the QProcess to make sure Lidar App Launcher opens:
    this->executeROSLidarApp = new QProcess(this);
    this->executeROSLidarApp->setProcessChannelMode(QProcess::MergedChannels);
    connect(this->executeROSLidarApp, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
            [this, script = this->executeROSLidarApp](int exitCode, QProcess::ExitStatus exitStatus){
            qDebug() << "[EXEC] FINISHED: " << exitCode << exitStatus;
            QByteArray newData = executeROSLidarApp->readAllStandardError();
            QString text = ui->textEditLidar->toPlainText() + QString::fromLocal8Bit(newData);
            ui->textEditLidar->setPlainText(text);
            qDebug() << text;
            //qDebug() << "[EXEC] FINISHED_2: " << QProcess::ExitStatus << exitStatus;
            //QString st = QVariant::fromValue(QProcess::ExitStatus).toString();
            if(script->bytesAvailable() > 0) qDebug() << "[EXEC] buffered DATA:" << script->readAll();
            ui->textEditLidar->setText("[EXEC] FINISHED: " + QString::number(exitCode) + " " + "[EXEC] buffered DATA: ");
    });
}

Also I came across this post, this other one, both advises to go for a QMetaEnum.

this source which brought me very very close to the solution but there is still something missing. This procedure seems to be going in the right direction but I don't get to see the string I am looking for.

Another possibility I tried was to go for:

QString st = QVariant::fromValue(QProcess::ExitStatus).toString(); 

or for

QString st = QVariant::fromValue(QProcess::ExitStatus).toStdString(); 

but none of them worked.

What am I missing? DO I have to go down the route of the QMetaEnum? Please advise on how to solve this issue.

Aucun commentaire:

Enregistrer un commentaire