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. no matching member function for call to 'connect'
Forum Updated to NodeBB v4.3 + New Features

no matching member function for call to 'connect'

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 2 Posters 3.1k Views
  • 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
    t.vanbesien
    wrote on last edited by t.vanbesien
    #1

    Hello,

    I am trying to use QSignalMapper to map many similar identifiable QLineEdit widgets in my program.
    I am following instructions on this page: https://doc.qt.io/qt-5/qsignalmapper.html#details
    However I get a compilation error (the title). I don't understand, QWidget inherits from QObject, so the member function exists, but I must be doing something wrong with the parameters. Help :)

    The line that produces this error is: (in the .cpp file)

    connect(lineEdit, &QLineEdit::editingFinished, signalMapper, &QSignalMapper::map);
    

    Here is the source code and header of the class I'm implementing:

    lineedityarnsetpoint.h

    #ifndef LINEEDITYARNSETPOINT_H
    #define LINEEDITYARNSETPOINT_H
    
    #include <QWidget>
    #include <QSignalMapper>
    #include <QLineEdit>
    #include <QGridLayout>
    //#include <QObject>
    
    class LineEditYarnSetpoint : public QWidget
    {
    	Q_OBJECT
    public:
    	LineEditYarnSetpoint(const int n, QWidget *parent = nullptr);
    
    signals:
    	void editingFinished(const int feeder_index);
    
    private:
    	QSignalMapper *signalMapper;
    
    };
    
    #endif // LINEEDITYARNSETPOINT_H
    

    lineedityarnsetpoint.cpp

    #include "lineedityarnsetpoint.h"
    
    LineEditYarnSetpoint::LineEditYarnSetpoint(const int n, QWidget *parent)
    	: QWidget(parent)
    {
    	signalMapper = new QSignalMapper(this);
    
    	QGridLayout *gridLayout = new QGridLayout;
    	for (int i = 0; i < n; ++i)
    	{
    		QLineEdit *lineEdit = new QLineEdit();
    		/*ERROR*/connect(lineEdit, &QLineEdit::editingFinished, signalMapper, &QSignalMapper::map);
    		signalMapper->setMapping(lineEdit, i);
    		gridLayout->addWidget(lineEdit, 0, i);
    	}
    	connect(signalMapper, &QSignalMapper::mappedInt, this, &LineEditYarnSetpoint::editingFinished);
    	setLayout(gridLayout);
    }
    

    Thanks in advance! :)

    JonBJ 1 Reply Last reply
    0
    • T t.vanbesien

      Hello,

      I am trying to use QSignalMapper to map many similar identifiable QLineEdit widgets in my program.
      I am following instructions on this page: https://doc.qt.io/qt-5/qsignalmapper.html#details
      However I get a compilation error (the title). I don't understand, QWidget inherits from QObject, so the member function exists, but I must be doing something wrong with the parameters. Help :)

      The line that produces this error is: (in the .cpp file)

      connect(lineEdit, &QLineEdit::editingFinished, signalMapper, &QSignalMapper::map);
      

      Here is the source code and header of the class I'm implementing:

      lineedityarnsetpoint.h

      #ifndef LINEEDITYARNSETPOINT_H
      #define LINEEDITYARNSETPOINT_H
      
      #include <QWidget>
      #include <QSignalMapper>
      #include <QLineEdit>
      #include <QGridLayout>
      //#include <QObject>
      
      class LineEditYarnSetpoint : public QWidget
      {
      	Q_OBJECT
      public:
      	LineEditYarnSetpoint(const int n, QWidget *parent = nullptr);
      
      signals:
      	void editingFinished(const int feeder_index);
      
      private:
      	QSignalMapper *signalMapper;
      
      };
      
      #endif // LINEEDITYARNSETPOINT_H
      

      lineedityarnsetpoint.cpp

      #include "lineedityarnsetpoint.h"
      
      LineEditYarnSetpoint::LineEditYarnSetpoint(const int n, QWidget *parent)
      	: QWidget(parent)
      {
      	signalMapper = new QSignalMapper(this);
      
      	QGridLayout *gridLayout = new QGridLayout;
      	for (int i = 0; i < n; ++i)
      	{
      		QLineEdit *lineEdit = new QLineEdit();
      		/*ERROR*/connect(lineEdit, &QLineEdit::editingFinished, signalMapper, &QSignalMapper::map);
      		signalMapper->setMapping(lineEdit, i);
      		gridLayout->addWidget(lineEdit, 0, i);
      	}
      	connect(signalMapper, &QSignalMapper::mappedInt, this, &LineEditYarnSetpoint::editingFinished);
      	setLayout(gridLayout);
      }
      

      Thanks in advance! :)

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @t-vanbesien said in no matching member function for call to 'connect':

      /*ERROR*/connect(lineEdit, &QLineEdit::editingFinished, signalMapper, &QSignalMapper::map);

      void QSignalMapper::map(QObject *sender) expects a QObject *sender parameter. void QLineEdit::editingFinished() does not provide one.

      OIC, void QSignalMapper::map() does not take any parameter. But now there are two slots of the same name which differ only by parameter. Then you may need to use qOverload<>()/QOverload<>::of() to specify which one? Maybe QOverload<>::of<>(&QSignalMapper::map) or QOverload<>::of<void>(&QSignalMapper::map)? (I don't know how you specify "the one with no parameter").

      Ah, see https://stackoverflow.com/questions/68552698/connecting-qsignalmapper-qt-5-15-2 ?

      Also, if you had copied and pasted the full error details from the compiler I think it would have said a bit more than just no matching member function for call to 'connect', does it not show information about the various possible slot method overloads?

      T 1 Reply Last reply
      1
      • JonBJ JonB

        @t-vanbesien said in no matching member function for call to 'connect':

        /*ERROR*/connect(lineEdit, &QLineEdit::editingFinished, signalMapper, &QSignalMapper::map);

        void QSignalMapper::map(QObject *sender) expects a QObject *sender parameter. void QLineEdit::editingFinished() does not provide one.

        OIC, void QSignalMapper::map() does not take any parameter. But now there are two slots of the same name which differ only by parameter. Then you may need to use qOverload<>()/QOverload<>::of() to specify which one? Maybe QOverload<>::of<>(&QSignalMapper::map) or QOverload<>::of<void>(&QSignalMapper::map)? (I don't know how you specify "the one with no parameter").

        Ah, see https://stackoverflow.com/questions/68552698/connecting-qsignalmapper-qt-5-15-2 ?

        Also, if you had copied and pasted the full error details from the compiler I think it would have said a bit more than just no matching member function for call to 'connect', does it not show information about the various possible slot method overloads?

        T Offline
        T Offline
        t.vanbesien
        wrote on last edited by
        #3

        @JonB

        Here is the full error message:

        /Users/thomasvanbesien/IHM_Bobink/lineedityarnsetpoint.cpp:14: error: no matching member function for call to 'connect'
        ../IHM_Bobink/lineedityarnsetpoint.cpp:14:3: error: no matching member function for call to 'connect'
                        connect(lineEdit, &QLineEdit::editingFinished, signalMapper, &QSignalMapper::map);
                        ^~~~~~~
        /Users/thomasvanbesien/Qt/6.4.2/macos/lib/QtCore.framework/Headers/qobject.h:181:36: note: candidate function not viable: no known conversion from 'void (QLineEdit::*)()' to 'const char *' for 2nd argument
            static QMetaObject::Connection connect(const QObject *sender, const char *signal,
                                           ^
        /Users/thomasvanbesien/Qt/6.4.2/macos/lib/QtCore.framework/Headers/qobject.h:184:36: note: candidate function not viable: no known conversion from 'void (QLineEdit::*)()' to 'const QMetaMethod' for 2nd argument
            static QMetaObject::Connection connect(const QObject *sender, const QMetaMethod &signal,
                                           ^
        /Users/thomasvanbesien/Qt/6.4.2/macos/lib/QtCore.framework/Headers/qobject.h:432:41: note: candidate function not viable: no known conversion from 'void (QLineEdit::*)()' to 'const char *' for 2nd argument
        inline QMetaObject::Connection QObject::connect(const QObject *asender, const char *asignal,
                                                ^
        /Users/thomasvanbesien/Qt/6.4.2/macos/lib/QtCore.framework/Headers/qobject.h:201:43: note: candidate template ignored: couldn't infer template argument 'Func2'
            static inline QMetaObject::Connection connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal,
                                                  ^
        /Users/thomasvanbesien/Qt/6.4.2/macos/lib/QtCore.framework/Headers/qobject.h:242:13: note: candidate template ignored: couldn't infer template argument 'Func2'
                    connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal, const QObject *context, Func2 slot,
                    ^
        /Users/thomasvanbesien/Qt/6.4.2/macos/lib/QtCore.framework/Headers/qobject.h:287:13: note: candidate template ignored: couldn't infer template argument 'Func2'
                    connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal, const QObject *context, Func2 slot,
                    ^
        /Users/thomasvanbesien/Qt/6.4.2/macos/lib/QtCore.framework/Headers/qobject.h:233:13: note: candidate function template not viable: requires 3 arguments, but 4 were provided
                    connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal, Func2 slot)
                    ^
        /Users/thomasvanbesien/Qt/6.4.2/macos/lib/QtCore.framework/Headers/qobject.h:276:13: note: candidate function template not viable: requires 3 arguments, but 4 were provided
                    connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal, Func2 slot)
                    ^
        
        JonBJ 1 Reply Last reply
        0
        • T t.vanbesien

          @JonB

          Here is the full error message:

          /Users/thomasvanbesien/IHM_Bobink/lineedityarnsetpoint.cpp:14: error: no matching member function for call to 'connect'
          ../IHM_Bobink/lineedityarnsetpoint.cpp:14:3: error: no matching member function for call to 'connect'
                          connect(lineEdit, &QLineEdit::editingFinished, signalMapper, &QSignalMapper::map);
                          ^~~~~~~
          /Users/thomasvanbesien/Qt/6.4.2/macos/lib/QtCore.framework/Headers/qobject.h:181:36: note: candidate function not viable: no known conversion from 'void (QLineEdit::*)()' to 'const char *' for 2nd argument
              static QMetaObject::Connection connect(const QObject *sender, const char *signal,
                                             ^
          /Users/thomasvanbesien/Qt/6.4.2/macos/lib/QtCore.framework/Headers/qobject.h:184:36: note: candidate function not viable: no known conversion from 'void (QLineEdit::*)()' to 'const QMetaMethod' for 2nd argument
              static QMetaObject::Connection connect(const QObject *sender, const QMetaMethod &signal,
                                             ^
          /Users/thomasvanbesien/Qt/6.4.2/macos/lib/QtCore.framework/Headers/qobject.h:432:41: note: candidate function not viable: no known conversion from 'void (QLineEdit::*)()' to 'const char *' for 2nd argument
          inline QMetaObject::Connection QObject::connect(const QObject *asender, const char *asignal,
                                                  ^
          /Users/thomasvanbesien/Qt/6.4.2/macos/lib/QtCore.framework/Headers/qobject.h:201:43: note: candidate template ignored: couldn't infer template argument 'Func2'
              static inline QMetaObject::Connection connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal,
                                                    ^
          /Users/thomasvanbesien/Qt/6.4.2/macos/lib/QtCore.framework/Headers/qobject.h:242:13: note: candidate template ignored: couldn't infer template argument 'Func2'
                      connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal, const QObject *context, Func2 slot,
                      ^
          /Users/thomasvanbesien/Qt/6.4.2/macos/lib/QtCore.framework/Headers/qobject.h:287:13: note: candidate template ignored: couldn't infer template argument 'Func2'
                      connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal, const QObject *context, Func2 slot,
                      ^
          /Users/thomasvanbesien/Qt/6.4.2/macos/lib/QtCore.framework/Headers/qobject.h:233:13: note: candidate function template not viable: requires 3 arguments, but 4 were provided
                      connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal, Func2 slot)
                      ^
          /Users/thomasvanbesien/Qt/6.4.2/macos/lib/QtCore.framework/Headers/qobject.h:276:13: note: candidate function template not viable: requires 3 arguments, but 4 were provided
                      connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal, Func2 slot)
                      ^
          
          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @t-vanbesien said in no matching member function for call to 'connect':

          couldn't infer template argument 'Func2'

          I'm not sure, but this is probably the one that relates to your situation.
          In any case you need to do the "qoverload" I suggested and is in the SO post.

          T 1 Reply Last reply
          1
          • JonBJ JonB

            @t-vanbesien said in no matching member function for call to 'connect':

            couldn't infer template argument 'Func2'

            I'm not sure, but this is probably the one that relates to your situation.
            In any case you need to do the "qoverload" I suggested and is in the SO post.

            T Offline
            T Offline
            t.vanbesien
            wrote on last edited by
            #5

            @JonB

            Thank you for the help. I was able to make it work, I changed the erroneous line to:

            connect(lineEdit, &QLineEdit::editingFinished, signalMapper, QOverload<>::of<>(&QSignalMapper::map));
            

            I'm not completely sure why it works. C++ templates are still a bit fuzzy to me, but I'll post an explanation when I understand exactly what the problem was.

            JonBJ 1 Reply Last reply
            0
            • T t.vanbesien

              @JonB

              Thank you for the help. I was able to make it work, I changed the erroneous line to:

              connect(lineEdit, &QLineEdit::editingFinished, signalMapper, QOverload<>::of<>(&QSignalMapper::map));
              

              I'm not completely sure why it works. C++ templates are still a bit fuzzy to me, but I'll post an explanation when I understand exactly what the problem was.

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #6

              @t-vanbesien said in no matching member function for call to 'connect':

              connect(lineEdit, &QLineEdit::editingFinished, signalMapper, QOverload<>::of<>(&QSignalMapper::map));

              I don't believe that is a working copy/paste, I think you mean QOverload<>::of(&QSignalMapper::map)?

              C++ templates are still a bit fuzzy to me, but I'll post an explanation when I understand exactly what the problem was.

              There are 2 possible overloads: QSignalMapper::map() & QSignalMapper::map(QObject *).
              QOverload<>::of(...) picks the first one (no parameters), QOverload<QObject *>::of(...) picks the second one. The bit inside <...> specifies the parameters. It's kind of like a cast.

              T 1 Reply Last reply
              1
              • JonBJ JonB

                @t-vanbesien said in no matching member function for call to 'connect':

                connect(lineEdit, &QLineEdit::editingFinished, signalMapper, QOverload<>::of<>(&QSignalMapper::map));

                I don't believe that is a working copy/paste, I think you mean QOverload<>::of(&QSignalMapper::map)?

                C++ templates are still a bit fuzzy to me, but I'll post an explanation when I understand exactly what the problem was.

                There are 2 possible overloads: QSignalMapper::map() & QSignalMapper::map(QObject *).
                QOverload<>::of(...) picks the first one (no parameters), QOverload<QObject *>::of(...) picks the second one. The bit inside <...> specifies the parameters. It's kind of like a cast.

                T Offline
                T Offline
                t.vanbesien
                wrote on last edited by
                #7

                @JonB said in no matching member function for call to 'connect':

                I don't believe that is a working copy/paste, I think you mean QOverload<>::of(&QSignalMapper::map)?

                No, the line I copy/pasted does compile and run and has the expected behavior.

                JonBJ 1 Reply Last reply
                0
                • T t.vanbesien

                  @JonB said in no matching member function for call to 'connect':

                  I don't believe that is a working copy/paste, I think you mean QOverload<>::of(&QSignalMapper::map)?

                  No, the line I copy/pasted does compile and run and has the expected behavior.

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by
                  #8

                  @t-vanbesien
                  Interesting. Could you tell me/give me a reference to where you got an example or documentation which uses QOverload<...>::of<...>(...) rather than QOverload<...>::of(...), please? Note the bit I am asking about is the ::of<> having a <...> segment?

                  T 1 Reply Last reply
                  1
                  • JonBJ JonB

                    @t-vanbesien
                    Interesting. Could you tell me/give me a reference to where you got an example or documentation which uses QOverload<...>::of<...>(...) rather than QOverload<...>::of(...), please? Note the bit I am asking about is the ::of<> having a <...> segment?

                    T Offline
                    T Offline
                    t.vanbesien
                    wrote on last edited by t.vanbesien
                    #9

                    @JonB
                    I don't know ? I'm not sure I understand the question. I used

                    QOverload<...>::of<...>()
                    

                    because you wrote it in your first answer to this post. I can't find any documentation about it. If you want a working example I can share the class .cpp and .h of the class and the small debug function I made to make sure it is working properly. You can put it in an empty qt project to check.

                    JonBJ 1 Reply Last reply
                    0
                    • T t.vanbesien

                      @JonB
                      I don't know ? I'm not sure I understand the question. I used

                      QOverload<...>::of<...>()
                      

                      because you wrote it in your first answer to this post. I can't find any documentation about it. If you want a working example I can share the class .cpp and .h of the class and the small debug function I made to make sure it is working properly. You can put it in an empty qt project to check.

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by
                      #10

                      @t-vanbesien said in no matching member function for call to 'connect':

                      because you wrote it in your first answer to this post.

                      Damn! So I did, I was guessing at that point! :( Now I know better, from the SO link I gave you :)

                      I suggest that you try copy/paste the following line to replace yours:

                      connect(lineEdit, &QLineEdit::editingFinished, signalMapper, QOverload<>::of(&QSignalMapper::map));
                      

                      Even though your ::of<>( apparently works, it should be ::of(. Don't confuse yourself by using my guessed-syntax, for when you come back to it.

                      T 1 Reply Last reply
                      1
                      • JonBJ JonB

                        @t-vanbesien said in no matching member function for call to 'connect':

                        because you wrote it in your first answer to this post.

                        Damn! So I did, I was guessing at that point! :( Now I know better, from the SO link I gave you :)

                        I suggest that you try copy/paste the following line to replace yours:

                        connect(lineEdit, &QLineEdit::editingFinished, signalMapper, QOverload<>::of(&QSignalMapper::map));
                        

                        Even though your ::of<>( apparently works, it should be ::of(. Don't confuse yourself by using my guessed-syntax, for when you come back to it.

                        T Offline
                        T Offline
                        t.vanbesien
                        wrote on last edited by
                        #11

                        @JonB

                        I replaced the line so that now it is:

                        connect(lineEdit, &QLineEdit::editingFinished, signalMapper, QOverload<>::of(&QSignalMapper::map));
                        

                        And everything is still working properly.

                        By the way, you wrote 'IOC' in one of your answers, what does it mean ?

                        JonBJ 1 Reply Last reply
                        1
                        • T t.vanbesien

                          @JonB

                          I replaced the line so that now it is:

                          connect(lineEdit, &QLineEdit::editingFinished, signalMapper, QOverload<>::of(&QSignalMapper::map));
                          

                          And everything is still working properly.

                          By the way, you wrote 'IOC' in one of your answers, what does it mean ?

                          JonBJ Offline
                          JonBJ Offline
                          JonB
                          wrote on last edited by
                          #12

                          @t-vanbesien said in no matching member function for call to 'connect':

                          By the way, you wrote 'IOC' in one of your answers, what does it mean ?

                          I wrote OIC => O-I-C => "Oh I See" :)

                          1 Reply Last reply
                          2

                          • Login

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