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. Connecting problem <unresolved overloaded function type>
Forum Updated to NodeBB v4.3 + New Features

Connecting problem <unresolved overloaded function type>

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 4 Posters 1.4k Views 2 Watching
  • 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.
  • Z Offline
    Z Offline
    zeroptr
    wrote on last edited by
    #1

    Hi All,

    I use Qsignal mapper in a form for buttons. When I try to connect them I have

    error: no matching function for call to 'QPushButton::connect(QPushButton*&, void (QAbstractButton::)(), QSignalMapper&, <unresolved overloaded function type>)'

    error: no matching function for call to 'QPushButton::connect(QPushButton*&, void (QAbstractButton::)(), QSignalMapper&, <unresolved overloaded function type>)'
    49 | buton->connect(buton, &QPushButton::pressed ,TheMapper, &QSignalMapper::map);
    | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

     QList<QPushButton *> widgetlist = this->findChildren<QPushButton  *>();
        foreach (QPushButton *buton, widgetlist) {
            if ((buton->toolTipDuration() > 0) && (buton->toolTipDuration() < 5000))  {
                //buton->connect(buton,SIGNAL(pressed()),TheMapper,SLOT(map()));
                buton->connect(buton, &QPushButton::pressed ,TheMapper, &QSignalMapper::map);
                TheMapper->setMapping(buton,buton->toolTipDuration());
                ObjectMap->insert(buton->toolTipDuration(),buton);
                itemslist->insert(buton->toolTipDuration(),new vitem);
                connect(qobject_cast<vitem*>(itemslist->value(buton->toolTipDuration())),&vitem::boolvaluechanged,
                        buton ,&QPushButton::setFlat);
    
                //qDebug()<< buton->objectName();
            }
    

    At Qt5 the commented connecting was working.. Any Solution?

    Linux Mint 20.04 64 Bit QT6.0.1

    sierdzioS 1 Reply Last reply
    0
    • JonBJ JonB

      @zeroptr
      Did you click on the https://doc.qt.io/qt-6/qoverload-proxy.html#qOverload link @sierdzio gave you? It shows you how to use qOverload() to specify which overload of a method which has multiple signatures you want to use.

      There are two possible slots:
      void QSignalMapper::map()
      void QSignalMapper::map(QObject *sender)
      You need to tell C++ which one to use.

      Z Offline
      Z Offline
      zeroptr
      wrote on last edited by zeroptr
      #6

      buton->connect(buton, &QPushButton::pressed ,TheMapper,qOverload<>(&QSignalMapper::map));

      solved

      Linux Mint 20.04 64 Bit QT6.0.1

      JonBJ 1 Reply Last reply
      0
      • Z zeroptr

        Hi All,

        I use Qsignal mapper in a form for buttons. When I try to connect them I have

        error: no matching function for call to 'QPushButton::connect(QPushButton*&, void (QAbstractButton::)(), QSignalMapper&, <unresolved overloaded function type>)'

        error: no matching function for call to 'QPushButton::connect(QPushButton*&, void (QAbstractButton::)(), QSignalMapper&, <unresolved overloaded function type>)'
        49 | buton->connect(buton, &QPushButton::pressed ,TheMapper, &QSignalMapper::map);
        | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

         QList<QPushButton *> widgetlist = this->findChildren<QPushButton  *>();
            foreach (QPushButton *buton, widgetlist) {
                if ((buton->toolTipDuration() > 0) && (buton->toolTipDuration() < 5000))  {
                    //buton->connect(buton,SIGNAL(pressed()),TheMapper,SLOT(map()));
                    buton->connect(buton, &QPushButton::pressed ,TheMapper, &QSignalMapper::map);
                    TheMapper->setMapping(buton,buton->toolTipDuration());
                    ObjectMap->insert(buton->toolTipDuration(),buton);
                    itemslist->insert(buton->toolTipDuration(),new vitem);
                    connect(qobject_cast<vitem*>(itemslist->value(buton->toolTipDuration())),&vitem::boolvaluechanged,
                            buton ,&QPushButton::setFlat);
        
                    //qDebug()<< buton->objectName();
                }
        

        At Qt5 the commented connecting was working.. Any Solution?

        sierdzioS Offline
        sierdzioS Offline
        sierdzio
        Moderators
        wrote on last edited by
        #2

        @zeroptr you probably need to use qOverload to tell connect() which function signature to pick.

        (Z(:^

        Z 1 Reply Last reply
        2
        • sierdzioS sierdzio

          @zeroptr you probably need to use qOverload to tell connect() which function signature to pick.

          Z Offline
          Z Offline
          zeroptr
          wrote on last edited by
          #3

          @sierdzio sorry I couldnot understand the use..

          Linux Mint 20.04 64 Bit QT6.0.1

          sierdzioS JonBJ 2 Replies Last reply
          0
          • Z zeroptr

            @sierdzio sorry I couldnot understand the use..

            sierdzioS Offline
            sierdzioS Offline
            sierdzio
            Moderators
            wrote on last edited by
            #4

            The functor-based connection syntax requires providing a pointer to signal and slot in connect call. But if you have overloaded functions, for example:

            public slots:
              void doSomething(int i);
              void doSomething(QString i);
            

            then functor syntax is ambiguous: &YouClass::doSomething might mean the integer or QString variant of the method. With qOverload you can specify exactly which method you mean to connect to.

            (Z(:^

            1 Reply Last reply
            2
            • Z zeroptr

              @sierdzio sorry I couldnot understand the use..

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

              @zeroptr
              Did you click on the https://doc.qt.io/qt-6/qoverload-proxy.html#qOverload link @sierdzio gave you? It shows you how to use qOverload() to specify which overload of a method which has multiple signatures you want to use.

              There are two possible slots:
              void QSignalMapper::map()
              void QSignalMapper::map(QObject *sender)
              You need to tell C++ which one to use.

              Z 1 Reply Last reply
              2
              • JonBJ JonB

                @zeroptr
                Did you click on the https://doc.qt.io/qt-6/qoverload-proxy.html#qOverload link @sierdzio gave you? It shows you how to use qOverload() to specify which overload of a method which has multiple signatures you want to use.

                There are two possible slots:
                void QSignalMapper::map()
                void QSignalMapper::map(QObject *sender)
                You need to tell C++ which one to use.

                Z Offline
                Z Offline
                zeroptr
                wrote on last edited by zeroptr
                #6

                buton->connect(buton, &QPushButton::pressed ,TheMapper,qOverload<>(&QSignalMapper::map));

                solved

                Linux Mint 20.04 64 Bit QT6.0.1

                JonBJ 1 Reply Last reply
                0
                • Z zeroptr has marked this topic as solved on
                • Z zeroptr

                  buton->connect(buton, &QPushButton::pressed ,TheMapper,qOverload<>(&QSignalMapper::map));

                  solved

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

                  @zeroptr
                  [EDIT: This reply posted before you latest "solved" post.]

                  Now I'm not sure what you're asking. QOverload(&QSignalMapper::map) simply does not exist, we never said QOverload(...).

                  I see that https://forum.qt.io/topic/93385/how-to-use-qoverload/4 says qOverload<> may not work on some Windows compilers, so let's use QOverload<>::of().

                  For your original I would expect

                  buton->connect(buton, &QPushButton::pressed ,TheMapper, QOverload<>::of(&QSignalMapper::map));
                  

                  That would pick the overload with no parameters, i.e. void QSignalMapper::map(). The QPushButton::pressed() signal does not pass a QObject *, so you can't call void QSignalMapper::map(QObject *sender).

                  1 Reply Last reply
                  0
                  • hskoglundH Offline
                    hskoglundH Offline
                    hskoglund
                    wrote on last edited by
                    #8

                    Hi, also consider switching to using lambdas instead of QSignalMapper (which seems to be on it's way out of Qt) say like this:

                    QList<QPushButton *> widgetlist = this->findChildren<QPushButton  *>();
                        foreach (QPushButton *buton, widgetlist) {
                            if ((buton->toolTipDuration() > 0) && (buton->toolTipDuration() < 5000))  {
                                buton->connect(buton, &QPushButton::pressed, this, [this, buton] { buton->setFlat(true); } );
                         
                                //qDebug()<< buton->objectName();
                            }
                    

                    Note: haven't tested this :-)

                    JonBJ 1 Reply Last reply
                    1
                    • hskoglundH hskoglund

                      Hi, also consider switching to using lambdas instead of QSignalMapper (which seems to be on it's way out of Qt) say like this:

                      QList<QPushButton *> widgetlist = this->findChildren<QPushButton  *>();
                          foreach (QPushButton *buton, widgetlist) {
                              if ((buton->toolTipDuration() > 0) && (buton->toolTipDuration() < 5000))  {
                                  buton->connect(buton, &QPushButton::pressed, this, [this, buton] { buton->setFlat(true); } );
                           
                                  //qDebug()<< buton->objectName();
                              }
                      

                      Note: haven't tested this :-)

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

                      @hskoglund
                      You are missing parentheses to help the OP get the syntax right:

                      [this, buton] () { buton->setFlat(true); }
                      

                      Here you could pass just buton in [...] context, this is not used. Though no harm done, just so the OP knows.

                      @zeroptr
                      Absolutely do move over from QSignalMapper to lambdas, much preferable.

                      hskoglundH 1 Reply Last reply
                      0
                      • JonBJ JonB

                        @hskoglund
                        You are missing parentheses to help the OP get the syntax right:

                        [this, buton] () { buton->setFlat(true); }
                        

                        Here you could pass just buton in [...] context, this is not used. Though no harm done, just so the OP knows.

                        @zeroptr
                        Absolutely do move over from QSignalMapper to lambdas, much preferable.

                        hskoglundH Offline
                        hskoglundH Offline
                        hskoglund
                        wrote on last edited by
                        #10

                        @JonB the parentheses are optional but I admit to be guilty of that unneeded this :=)

                        JonBJ 1 Reply Last reply
                        0
                        • hskoglundH hskoglund

                          @JonB the parentheses are optional but I admit to be guilty of that unneeded this :=)

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

                          @hskoglund said in Connecting problem <unresolved overloaded function type>:

                          the parentheses are optional

                          Wow, really? I never knew that!

                          1 Reply Last reply
                          0

                          • Login

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