1

I am trying to implement a custom QGraphicsScene, and when we press the left key, it allows dragging an item, for which I use QDrag and pass the item data, then I overwrite the dropEvent event where I get element and dropEvent new parent. I think that QGraphicsPixmapItem on top of another item could be tricky, so maybe the best option is to set it as the parentItem.

However, I get the following error 'auto' not allowed in lambda parameter and don't know exactly why

graphicsscene.h

protected:
    void mousePressEvent(QGraphicsSceneMouseEvent *event) override;

graphicsscene.cpp

void GraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
    auto its =  items(QRectF(event->scenePos() - QPointF(1,1), QSize(3,3)));
    auto val = std::find_if(its.constBegin(), its.constEnd(), [](auto const& it){ // <-- ERROR HERE
        return it->type() > QGraphicsItem::UserType;
    });
    if(val == its.constEnd())
        return;
    if(event->button() == Qt::RightButton){
        showContextMenu(event->scenePos());
    }
    else{
        createDrag(event->scenePos(), event->widget(), *val);
    }
}

Thanks for any insight about this.

Emanuele
  • 2,194
  • 6
  • 32
  • 71

1 Answers1

1

Generic lambdas are not supported in C++11. That means you cannot have a parameter with an auto type.

Simply update to C++14:

QMAKE_CXXFLAGS += -std=c++14

This will require at least GCC 5.

Generic lambdas are a bit more tricky to support than simple lambdas because they require a template to be implemented as the lambda closure.


If you want to stay with C++11, you'll have to specify the type of your function parameter directly:

auto val = std::find_if(
    its.constBegin(),
    its.constEnd(),
    [](Item const& it) { // let Item be the 
                         // type of (*its.constBegin())
    }
);
Guillaume Racicot
  • 39,621
  • 9
  • 77
  • 141