Important: Please read the Qt Code of Conduct -

Signal slot connection does not work with Move Semantics

  • Here I present simple code, which represents a problem

    #include <QCoreApplication>
    #include <QList>
    struct Data {
        int data;
    class Obj: public QObject {
        Obj() : QObject(nullptr) {
            connect(this, &Obj::startMove, this, &Obj::receiveData);
        void emitMoveOp() {
            QList<Data> data;
            emit startMove(std::move(data));
    public slots:
        void receiveData(QList<Data> && data) {
            dataList = data;
        void startMove(QList<Data> && data);
        QList<Data> dataList;
    int main(int argc, char *argv[])
        QCoreApplication a(argc, argv);
        Obj obj;
        return a.exec();

    I am getting an error caused by some problem with connection D:\dev\tools\Qt\5.9.1\mingw53_32\include\QtCore\qobjectdefs_impl.h:136: error: forming pointer to reference type 'QtPrivate::RemoveRef<QList<Data>&&>::Type {aka QList<Data>&&}' (o->*f)((*reinterpret_cast<typename RemoveRef<SignalArgs>::Type *>(arg[II+1]))...), ApplyReturnValue<R>(arg[0]); ^
    How to make signal slot connection work with rvalues?

  • Hi @Kofr

    I would guess that move semantics is not supported by the signal slot mechanism.


  • QList uses shared data, there is basically no advantage in using move semantic. Switch to the good old const QList<Data>& data

  • @m.sue the question is why?

  • @Kofr said in Signal slot connection does not work with Move Semantics:

    the question is why?

    if you check the moc output it's pretty clear. Arguments are "stored" as void* and then casted to the correct type (QList<Data>) and passed to the slot that can't receive it as it only accepts QList<Data>&&


  • @VRonin

    Yeah. The gerrit commits listed in the bug report you quoted show that move semantics are already implemented and even used in the development branch of Qt:

    So we will not have to wait for long.


Log in to reply