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. connect() does not take signalMapper as slot

connect() does not take signalMapper as slot

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 780 Views 1 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.
  • D Offline
    D Offline
    dalishi
    wrote on last edited by
    #1

    Hi, I'm using almost the same code from QSignalMapper document

    signalMapper = new QSignalMapper(this);
    QPushButton *button = new QPushButton("test");
    connect(button, &QPushButton::clicked, signalMapper, &QSignalMapper::map);
    

    However I got error:

    configdialog.cpp:89:5: No matching member function for call to 'connect'
    qobject.h:222:36: candidate function not viable: no known conversion from 'void (QAbstractButton::*)(bool)' to 'const char *' for 2nd argument
    qobject.h:225:36: candidate function not viable: no known conversion from 'void (QAbstractButton::*)(bool)' to 'const QMetaMethod' for 2nd argument
    qobject.h:481:41: candidate function not viable: no known conversion from 'void (QAbstractButton::*)(bool)' to 'const char *' for 2nd argument
    qobject.h:242:43: candidate template ignored: couldn't infer template argument 'Func2'
    qobject.h:283:13: candidate template ignored: couldn't infer template argument 'Func2'
    qobject.h:322:13: candidate template ignored: couldn't infer template argument 'Func2'
    qobject.h:274:13: candidate function template not viable: requires 3 arguments, but 4 were provided
    qobject.h:314:13: candidate function template not viable: requires 3 arguments, but 4 were provided
    

    My other connect() works all fine except QSignalMapper. Am I not using it correctly? Thanks.

    JonBJ 1 Reply Last reply
    0
    • D dalishi

      Hi, I'm using almost the same code from QSignalMapper document

      signalMapper = new QSignalMapper(this);
      QPushButton *button = new QPushButton("test");
      connect(button, &QPushButton::clicked, signalMapper, &QSignalMapper::map);
      

      However I got error:

      configdialog.cpp:89:5: No matching member function for call to 'connect'
      qobject.h:222:36: candidate function not viable: no known conversion from 'void (QAbstractButton::*)(bool)' to 'const char *' for 2nd argument
      qobject.h:225:36: candidate function not viable: no known conversion from 'void (QAbstractButton::*)(bool)' to 'const QMetaMethod' for 2nd argument
      qobject.h:481:41: candidate function not viable: no known conversion from 'void (QAbstractButton::*)(bool)' to 'const char *' for 2nd argument
      qobject.h:242:43: candidate template ignored: couldn't infer template argument 'Func2'
      qobject.h:283:13: candidate template ignored: couldn't infer template argument 'Func2'
      qobject.h:322:13: candidate template ignored: couldn't infer template argument 'Func2'
      qobject.h:274:13: candidate function template not viable: requires 3 arguments, but 4 were provided
      qobject.h:314:13: candidate function template not viable: requires 3 arguments, but 4 were provided
      

      My other connect() works all fine except QSignalMapper. Am I not using it correctly? Thanks.

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

      @dalishi
      I think: We are dealing with overloads of QSignaller::map() method. Doc example may not be up-to-date? Try:

      QOverload<>::of(&QSignalMapper::map)
      

      Does that fix?
      See https://stackoverflow.com/questions/68552698/connecting-qsignalmapper-qt-5-15-2.

      D 1 Reply Last reply
      2
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #3

        JonB beat me to it. :)

        connect(button, &QPushButton::clicked, signalMapper, qOverload<>(&QSignalMapper::map) );

        JonBJ D 2 Replies Last reply
        2
        • mrjjM mrjj

          JonB beat me to it. :)

          connect(button, &QPushButton::clicked, signalMapper, qOverload<>(&QSignalMapper::map) );

          JonBJ Online
          JonBJ Online
          JonB
          wrote on last edited by JonB
          #4

          @mrjj So are you volunteering to report it as a docs bug? :) Or @dalishi may care to do so.

          D 1 Reply Last reply
          1
          • JonBJ JonB

            @dalishi
            I think: We are dealing with overloads of QSignaller::map() method. Doc example may not be up-to-date? Try:

            QOverload<>::of(&QSignalMapper::map)
            

            Does that fix?
            See https://stackoverflow.com/questions/68552698/connecting-qsignalmapper-qt-5-15-2.

            D Offline
            D Offline
            dalishi
            wrote on last edited by
            #5

            @JonB Hi thanks for the reply. It seems working at least syntax-wise :)

            1 Reply Last reply
            0
            • mrjjM mrjj

              JonB beat me to it. :)

              connect(button, &QPushButton::clicked, signalMapper, qOverload<>(&QSignalMapper::map) );

              D Offline
              D Offline
              dalishi
              wrote on last edited by
              #6

              @mrjj it seems we need ::of here as in @JonB 's post. Otherwise we get the error:

              configdialog.cpp:91:71: Address of overloaded function 'map' does not match required type 'QOverload<>'
              qsignalmapper.h:85:10: candidate function
              qsignalmapper.h:86:10: candidate function
              

              and it is QOverload<> not qOverload<> tho, haha, thanks.

              1 Reply Last reply
              1
              • JonBJ JonB

                @mrjj So are you volunteering to report it as a docs bug? :) Or @dalishi may care to do so.

                D Offline
                D Offline
                dalishi
                wrote on last edited by
                #7

                @JonB i reported a bug but im first time so not sure whether im doing it correctly. Link is here

                JonBJ 1 Reply Last reply
                3
                • D dalishi

                  @JonB i reported a bug but im first time so not sure whether im doing it correctly. Link is here

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

                  @dalishi
                  All good, looks fine. I appended a post to clarify what exactly the statement in the example should read.

                  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