lundi 31 juillet 2017

Signals and slots with std::vector : lvalue issue

In one of my project, I am trying to use the Qt signals and slots mechanism with a std::vector<bool> as parameter. My project is equivalent to the following minimal code :

class App

// app.h
#ifndef APP_H
#define APP_H

#include <QObject>
#include <QSharedPointer>

#include "emitter.h"
#include "receiver.h"

class App : public QObject
{
    Q_OBJECT
public:
    App(QObject *parent = 0);

};

#endif // APP_H

// app.cpp

#include "app.h"

App::App(QObject* parent): QObject(parent)
{
    Emitter emitter;
    Receiver receiver;

    receiver.attachEmitter(emitter);
    emitter.run();
}

class Emitter

//emitter.h
#ifndef EMITTER_H
#define EMITTER_H

#include <QObject>
#include <vector>
#include "helper.h"

class Helper;

class Emitter : public QObject
{
    Q_OBJECT
public:
    explicit Emitter(QObject *parent = 0);
    void run();
signals:
    void triggered(std::vector<bool> value);
};

#endif // EMITTER_H

// emitter.cpp
#include "emitter.h"

Emitter::Emitter(QObject *parent) : QObject(parent)
{

}

void Emitter::run()
{
    emit triggered(Helper::value());
}

class Receiver

//receiver.h
#ifndef RECEIVER_H
#define RECEIVER_H

#include <QObject>
#include <QDebug>

#include <QSharedPointer>
#include "emitter.h"

class Emitter;

class Receiver : public QObject
{
    Q_OBJECT
public:
    explicit Receiver(QObject *parent = 0);
    void attachEmitter(QSharedPointer<Emitter> emitter);
signals:

public slots:
};

//receiver.cpp
#include "receiver.h"

Receiver::Receiver(QObject *parent) : QObject(parent)
{

}

void Receiver::attachEmitter(QSharedPointer<Emitter> emitter)
{
    connect(emitter.data(), &Emitter::triggered, [this](std::vector<bool> value) {
        qDebug() << "Received value";
    });
}

For some reason, the compiler doesn't like it at all and prints me this stack : Error stack

What do I have to do ? Thank you

Aucun commentaire:

Enregistrer un commentaire