Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved Utiliser une commande lambda avec connect

    French
    connect problem lambda
    4
    9
    405
    Loading More Posts
    • 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.
    • F
      Futuray Programming last edited by

      Bonjour,
      j'essaye d'utiliser un QOject::connect pour modifier une variable de type int :

      QObject::connect(bouton, SIGNAL(clicked()), this, [this](){
        variable++;
      });
      

      Or, cela me sort plusieurs erreurs :

      no matching function for call to ‘OptionMenuView::connect(QPushButton*&, const char*, vue*, vue::vue(QWidget*)::<lambda(int)>)’
            |     });
            |      ^
      

      et

      erreur : no type named ‘Object’ in ‘struct QtPrivate::FunctionPointer<OptionMenuView::OptionMenuView(QWidget*)::<lambda(int)> >’
      In file included from /home/-/Qt/6.4.1/gcc_64/include/QtWidgets/qgraphicsitem.h:8,
                       from /home/-/Qt/6.4.1/gcc_64/include/QtWidgets/QGraphicsItem:1,
                       from /home/-/-/rpg/main/optionmenuview.h:4,
                       from /home/-/-/rpg/main/optionmenuview.cpp:1:
      /home/-/Qt/6.4.1/gcc_64/include/QtCore/qobject.h:181:36: note: candidate: ‘static QMetaObject::Connection QObject::connect(const QObject*, const char*, const QObject*, const char*, Qt::ConnectionType)’
        181 |     static QMetaObject::Connection connect(const QObject *sender, const char *signal,
            |                                    ^~~~~~~
      /home/-/Qt/6.4.1/gcc_64/include/QtCore/qobject.h:182:62: note:   no known conversion for argument 4 from ‘OptionMenuView::OptionMenuView(QWidget*)::<lambda(int)>’ to ‘const char*’
        182 |                         const QObject *receiver, const char *member, Qt::ConnectionType = Qt::AutoConnection);
            |                                                  ~~~~~~~~~~~~^~~~~~
      /home/-/Qt/6.4.1/gcc_64/include/QtCore/qobject.h:184:36: note: candidate: ‘static QMetaObject::Connection QObject::connect(const QObject*, const QMetaMethod&, const QObject*, const QMetaMethod&, Qt::ConnectionType)’
        184 |     static QMetaObject::Connection connect(const QObject *sender, const QMetaMethod &signal,
            |                                    ^~~~~~~
      /home/-/Qt/6.4.1/gcc_64/include/QtCore/qobject.h:184:86: note:   no known conversion for argument 2 from ‘const char*’ to ‘const QMetaMethod&’
        184 |     static QMetaObject::Connection connect(const QObject *sender, const QMetaMethod &signal,
            |                                                                   ~~~~~~~~~~~~~~~~~~~^~~~~~
      /home/sit/Qt/6.4.1/gcc_64/include/QtCore/qobject.h:432:32: note: candidate: ‘QMetaObject::Connection QObject::connect(const QObject*, const char*, const char*, Qt::ConnectionType) const’
        432 | inline QMetaObject::Connection QObject::connect(const QObject *asender, const char *asignal,
            |                                ^~~~~~~
      /home/-/Qt/6.4.1/gcc_64/include/QtCore/qobject.h:433:57: note:   no known conversion for argument 3 from ‘OptionMenuView*’ to ‘const char*’
        433 |                                             const char *amember, Qt::ConnectionType atype) const
            |                                             ~~~~~~~~~~~~^~~~~~~
      /home/-/Qt/6.4.1/gcc_64/include/QtCore/qobject.h:201:43: note: candidate: ‘template<class Func1, class Func2> static QMetaObject::Connection QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, const typename QtPrivate::FunctionPointer<Func2>::Object*, Func2, Qt::ConnectionType)’
        201 |     static inline QMetaObject::Connection connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal,
            |                                           ^~~~~~~
      /home/-/Qt/6.4.1/gcc_64/include/QtCore/qobject.h:201:43: note:   template argument deduction/substitution failed:
      /home/-/Qt/6.4.1/gcc_64/include/QtCore/qobject.h: In substitution of ‘template<class Func1, class Func2> static QMetaObject::Connection QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, const typename QtPrivate::FunctionPointer<Func2>::Object*, Func2, Qt::ConnectionType) [with Func1 = const char*; Func2 = OptionMenuView::OptionMenuView(QWidget*)::<lambda(int)>]’:
      /home/-/nicolas/rpg/main/optionmenuview.cpp:33:6:   required from here
      /home/-/Qt/6.4.1/gcc_64/include/QtCore/qobject.h:201:43: error: no type named ‘Object’ in ‘struct QtPrivate::FunctionPointer<OptionMenuView::OptionMenuView(QWidget*)::<lambda(int)> >’
      /home/-/Qt/6.4.1/gcc_64/include/QtCore/qobject.h:233:13: note: candidate: ‘template<class Func1, class Func2> static typename std::enable_if<((int)(QtPrivate::FunctionPointer<Func2>::ArgumentCount) >= 0), QMetaObject::Connection>::type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, Func2)’
        233 |             connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal, Func2 slot)
            |             ^~~~~~~
      /home/-/Qt/6.4.1/gcc_64/include/QtCore/qobject.h:233:13: note:   template argument deduction/substitution failed:
      /home/-/-/-/main/optionmenuview.cpp:33:6: note:   candidate expects 3 arguments, 4 provided
            |     });
            |      ^
      

      et encore 2 autres très similaires.
      Si quelqu'un peut m'aider, je le remercie d'avance.

      M JonB 2 Replies Last reply Reply Quote 0
      • Topic is now a regular thread  F Futuray Programming 
      • Topic has been marked as a question  F Futuray Programming 
      • JonB
        JonB @Futuray Programming last edited by JonB

        @Futuray-Programming
        On ne peut pas avoir SIGNAL/SLOT() macros avec le connect() moderne qui permet un lambda:

        QObject::connect(bouton, &QPushButton::clicked, this, [this](){
        

        Ne utilisez plus le syntaxe ancien avec les macros.
        N'utilisez plus l'ancienne syntaxe avec les macros.

        M 1 Reply Last reply Reply Quote 3
        • M
          mpergand @Futuray Programming last edited by

          @Futuray-Programming said in Utiliser une commande lambda avec connect:

          QObject::connect(bouton, SIGNAL(clicked()), this, this{
          variable++;
          });

          Essaye avec la nouvelle syntaxe:

          connect(bouton, &QPushButton::clicked, this, [this](){
            variable++;
          });
          
          1 Reply Last reply Reply Quote 2
          • JonB
            JonB @Futuray Programming last edited by JonB

            @Futuray-Programming
            On ne peut pas avoir SIGNAL/SLOT() macros avec le connect() moderne qui permet un lambda:

            QObject::connect(bouton, &QPushButton::clicked, this, [this](){
            

            Ne utilisez plus le syntaxe ancien avec les macros.
            N'utilisez plus l'ancienne syntaxe avec les macros.

            M 1 Reply Last reply Reply Quote 3
            • M
              mpergand @JonB last edited by mpergand

              @JonB said in Utiliser une commande lambda avec connect:

              Ne utilisez plus le syntaxe ancien avec les macros.

              En bon français:
              N'utilisez plus l'ancienne syntaxe avec les macros.
              :)

              JonB 1 Reply Last reply Reply Quote 1
              • JonB
                JonB @mpergand last edited by

                @mpergand Soupir :) Merci, je l'ai corrigé

                1 Reply Last reply Reply Quote 0
                • F
                  Futuray Programming last edited by Futuray Programming

                  Ah oui, en effet, je ne connaissais pas la nouvelle syntaxe.
                  Je vais mètre à jour tout le code du coup.
                  👍

                  M 1 Reply Last reply Reply Quote 1
                  • M
                    mpergand @Futuray Programming last edited by

                    @Futuray-Programming said in Utiliser une commande lambda avec connect:

                    Je vais mètre à jour tout le code du coup.

                    Combien de mètres de code ? :)

                    F 1 Reply Last reply Reply Quote 0
                    • F
                      Futuray Programming @mpergand last edited by

                      @mpergand Ah, oui oups...
                      😑

                      1 Reply Last reply Reply Quote 0
                      • Topic has been marked as solved  F Futuray Programming 
                      • GrecKo
                        GrecKo Qt Champions 2018 last edited by

                        Nouvelle syntaxe qui a 10 ans pour info ;)

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post