【发布时间】:2020-09-24 23:21:53
【问题描述】:
我正在尝试将 qDebug() 语句的结果传递给 QTextEdit 但没有成功,因为我收到了 'This' cannot be implicitly captured in this context 的编译器错误,而且我以前从未遇到过此错误。
然后输出在执行QProcess 后出现,并想在QTextEdit 上显示它,我在下面:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
startLidar();
ui->textEditLidar->setText("[STATUS] NO PROCESS STARTED: ");
ui->textEditGUI->setText("[STATUS] NO PROCESS STARTED: ");
}
MainWindow::~MainWindow()
{
delete ui;
}
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),
[script = this->executeROSLidarApp](int exitCode, QProcess::ExitStatus exitStatus){
qDebug() << "[EXEC] FINISHED: " << exitCode << exitStatus;
if(script->bytesAvailable() > 0) qDebug() << "[EXEC] buffered DATA:" << script->readAll();
ui->textEditLidar->setText("would like to see the output of the exitCode and exitStatus"); // <-- error here
});
connect(this->executeROSLidarApp, &QProcess::errorOccurred, [script = this->executeROSLidarApp](QProcess::ProcessError error) {
qDebug() << "[EXEC] error on execution: " << error << script->errorString();
ui->textEditLidar->setText("would like to see the output of the error"); // <-- error here
});
}
我认为这与我使用的不同 C++ 版本有关。我一直在使用C++11,它似乎与可能的 lambda 函数编译错误有关。
我一直在尝试研究这个错误,并遇到了this source、this additional 源,一切似乎都导致了不同版本之间的不匹配。如果需要,我还可以包含我的 .pro 文件。
感谢您阐明此问题并指出解决此问题的正确方向。
【问题讨论】:
标签: c++ qt c++11 qt5 qtextedit