Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [closed] using lambdas
Forum Updated to NodeBB v4.3 + New Features

[closed] using lambdas

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 2.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Timmoth
    wrote on last edited by
    #1

    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());
    });
    @

    1 Reply Last reply
    0
    • P Offline
      P Offline
      PeerS
      wrote on last edited by
      #2

      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 {};
      };@

      1 Reply Last reply
      0
      • T Offline
        T Offline
        Timmoth
        wrote on last edited by
        #3

        @
        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);
        }
        

        @

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          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/

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved