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. Qt5 new signals-slots syntax does not work [SOLVED]

Qt5 new signals-slots syntax does not work [SOLVED]

Scheduled Pinned Locked Moved General and Desktop
11 Posts 5 Posters 27.4k 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.
  • A Offline
    A Offline
    anaksimandr
    wrote on 30 Oct 2012, 11:39 last edited by
    #1

    Why this works
    @connect(cmbList1, SIGNAL(currentIndexChanged(const QString&)),this, SLOT(func1(const QString&)));@

    but this does not?
    @connect(cmbList1, &QComboBox::currentIndexChanged, this, &MyClass::func1);@

    log
    error: C2664: 'QMetaObject::Connection QObject::connect(const QObject *,const char *,const QObject *,const char *,Qt::ConnectionType)' : cannot convert parameter 2 from 'overloaded-function' to 'const char *'
    Context does not allow for disambiguation of overloaded function

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on 30 Oct 2012, 12:57 last edited by
      #2

      Are you sure you are using Qt5 (and not Qt4)?

      1 Reply Last reply
      0
      • A Offline
        A Offline
        anaksimandr
        wrote on 30 Oct 2012, 13:04 last edited by
        #3

        yes. at other place this method works

        1 Reply Last reply
        0
        • C Offline
          C Offline
          cincirin
          wrote on 30 Oct 2012, 13:10 last edited by
          #4

          Note that QComboBox::currentIndexChanged has two signals. Compiler don't know what signal do you want. Need to explicitly tell the compiler correct functions address.

          edit: for example for signal with QString argument, you need something like this:
          @
          void (QComboBox:: *indexChangedSignal)(QString) = &QComboBox::currentIndexChanged;
          connect(comboBox, indexChangedSignal, this, &MyClass::func1)
          @

          1 Reply Last reply
          2
          • A Offline
            A Offline
            anaksimandr
            wrote on 30 Oct 2012, 16:40 last edited by
            #5

            when i tried to compile code above i have this
            error: C2440: 'initializing' : cannot convert from 'overloaded-function' to 'void (__thiscall QComboBox::* )(QString)'
            None of the functions with this name in scope match the target type

            1 Reply Last reply
            0
            • A Offline
              A Offline
              anaksimandr
              wrote on 30 Oct 2012, 16:47 last edited by
              #6

              @connect(cmbProfiles, SIGNAL(currentIndexChanged(const QString&)),
              this, SLOT(loadProfilesDetails(const QString&)));@
              And now I see that in qt5 this code does not work too, it compiles but does not work. Sorry for my inattention.

              1 Reply Last reply
              0
              • A Offline
                A Offline
                anaksimandr
                wrote on 30 Oct 2012, 17:34 last edited by
                #7

                So now I must ask how to connect func to signal QComboBox::currentIndexChanged(const QString & text) in Qt5 ?

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  lgeyer
                  wrote on 30 Oct 2012, 19:20 last edited by SGaist
                  #8

                  As cincirin already mentioned you will have to explicitly cast overloaded signals when using the function pointer syntax.

                  connect(cmbProfiles,
                          static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged), 
                          this,
                          &MyClass::loadProfilesDetails);
                  

                  The equivalent of the string-based syntax is

                  connect(cmbProfiles, 
                          SIGNAL(currentIndexChanged(const QString &)),
                          this,
                          SLOT(loadProfilesDetails(const QString &)));
                  

                  or

                  connect(cmbProfiles, 
                          SIGNAL(currentIndexChanged(QString)),
                          this,
                          SLOT(loadProfilesDetails(QString)));
                  
                  1 Reply Last reply
                  2
                  • A Offline
                    A Offline
                    anaksimandr
                    wrote on 30 Oct 2012, 19:32 last edited by
                    #9

                    It works, thanks to all.

                    1 Reply Last reply
                    0
                    • P Offline
                      P Offline
                      Ph0t0n
                      wrote on 19 Jun 2015, 21:03 last edited by
                      #10

                      Wow... it works, but that is really ugly!

                      1 Reply Last reply
                      0
                      • J Offline
                        J Offline
                        j-hap
                        wrote on 29 Sept 2023, 12:46 last edited by j-hap
                        #11

                        I know this is quite old, but if someone ends up here again, this is the up-to-date way of defining an overload when connecting an overloaded signal: QOverload<int>::of(&QComboBox::currentIndexChanged)

                        1 Reply Last reply
                        1

                        • Login

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