c++ - Qt5 - C++11:“This”不能在这个上下文中被隐式捕获
问题描述
我试图将qDebug()
语句的结果传递给 aQTextEdit
但没有成功,因为我遇到了编译器错误,'This' cannot be implicitly captured in this context
而且我以前从未遇到过此错误。
然后输出在执行 a 后出现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 函数编译错误有关。我一直在尝试研究这个错误并遇到了这个来源,这个额外的来源和一切似乎都导致了不同版本之间的不匹配。如果需要,我还可以包含我的.pro
文件。
感谢您阐明此问题并指出解决此问题的正确方向。
解决方案
您的 lambda 没有捕获这一点(正如错误消息告诉您的那样),但您正在尝试访问它(ui->textEditLidar->...)
推荐阅读
- mysql - 如何正确命名数据库列
- android-studio - 在 Android Studio 中使用全屏时隐藏第二个显示器上的任务栏
- python - 我想用 spotify 库从我所有喜欢的歌曲中制作一个播放列表
- sql-server - 将 yyyy-mm-dd-hh.mm.ss.ms 字符串转换为日期时间
- c - 学校c项目中的字符串BUG
- laravel - 如何获取我从 Laravel 上的 getRoutes 方法获得的路线的 guarded_name
- sql-server - 将 SQL SERVER 查询更改为 POSTGRES
- mysql - 运行总计,但使用常量而不是当前行添加前一行
- c# - 如何为我的播放器实现 2 种不同的下落速度?
- c# - 如何调用一个函数是一个脚本来自另一个脚本的统一