[closed] using lambdas
-
Hi i was wondering why i am getting this error:
"error: C3493: 'd' cannot be implicitly captured because no default capture mode has been specified"
when i try to use this line of code:
@ QObject::connect(button, &QPushButton::clicked, [this] () {
Hi(d.absoluteFilePath());
});
@ -
How is d declared? Can you show a bit more of your code?
You have to tell the lambda how to capture d.
Assuming d is a local variable:
@
(1) auto l = &d { // d is captured by reference };
(2) auto l = d { // d is captured by value };
(3) auto l = & { // all available variables are captured by reference };
(4) auto l = = { // all available variables are captured by value };
@Or is d a member variable?
@struct MyClass
{
int foo() {
auto l = this{return d;};
return l();
};
int d {};
};@ -
@
QDir drives;
foreach(QFileInfo d, drives.drives())
{
QFileIconProvider ip;QVBoxLayout* buttonLayout = new QVBoxLayout; QPushButton *button = new QPushButton; button->setStyleSheet("border : 1px solid gray;" "background: transparent;"); button->setFixedSize(64,64); QLabel* iconLabel = new QLabel(); iconLabel->setTextInteractionFlags(Qt::NoTextInteraction); iconLabel->setPixmap(ip.icon(d).pixmap(16,16,QIcon::Normal, QIcon::On)); iconLabel->setAlignment(Qt::AlignCenter); iconLabel->setStyleSheet("border : 0px"); QLabel* textLabel = new QLabel(); textLabel->setTextInteractionFlags(Qt::NoTextInteraction); textLabel->setWordWrap(true); textLabel->setText(d.absoluteFilePath()); textLabel->setAlignment(Qt::AlignCenter); textLabel->setStyleSheet("border : 0px;"); buttonLayout->addWidget(iconLabel); buttonLayout->addWidget(textLabel); button->setLayout(buttonLayout); QObject::connect(button, &QPushButton::clicked, [this] () { Hi(d.absoluteFilePath()); }); quickLinks->addWidget(button); }
@
-
We do not allow opening a new topic for the same issue you already have a topic on. Please continue the discussion "here":/forums/viewthread/30789/