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]
QtWS25 Last Chance

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.
  • L Offline
    L Offline
    lgeyer
    wrote on 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 last edited by
      #3

      yes. at other place this method works

      1 Reply Last reply
      0
      • C Offline
        C Offline
        cincirin
        wrote on 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 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 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 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 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 last edited by
                  #9

                  It works, thanks to all.

                  1 Reply Last reply
                  0
                  • P Offline
                    P Offline
                    Ph0t0n
                    wrote on 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 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