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 overloaded signals to overloaded slots fails
Qt 6.11 is out! See what's new in the release blog

connecting overloaded signals to overloaded slots fails

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 5.4k 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.
  • U Offline
    U Offline
    user4592357
    wrote on last edited by user4592357
    #1

    i have two signals:

    void someSignal();
    void someSignal(SomeType type);
    

    and two slots in another class:

    void onSomeSignal();
    void onSomeSignal(ThatClass::SomeType type);
    

    but when i connect them like this:

    connect(widget, qOverload<>(&ThatClass::someSignal,
       this, qOverload<>(&ThisClass::onSomeSignal));
    connect(widget, qOverload<ThatClass::Type>(&ThatClass::someSignal),
       this, qOverload<ThatClass::Type>(&ThisClass::onSomeSignal));
    

    i get this error:

    error: no match for call to (const QOverload<>) (<unresolved overloaded function type>, ThisClass *, void (ThisClass::*)())
        this, qOverload<>(&ThisClass::onSomeSignal));
                                                  ^
    

    also found this somewhere in error:

    types R (T::)() const and void (ThatClass::)(ThatClass::Type) have incompatible cv-qualifiers
    

    any idea?

    i've also tried to use the old connect style. in that case the first connection (without args) succeeded, the second one (with args) failed.

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      I don't see a major mistake above. Please provide a compilable example.
      It does not work with the old style since your signal does not fully qualify the type and therefore the string comparison fails.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      0
      • U Offline
        U Offline
        user4592357
        wrote on last edited by user4592357
        #3

        i think this will do. what i have is similar, but this one compiles fine.
        EDIT: found out the problem, in the first connect in what i have i hadn't put a parentheses after signal name...

        // header.h
        class Widget : public QWidget
        {
        	Q_OBJECT
        public:
        	enum Type { ERR };
        	Widget()
        	{
        		emit someSignal();
        		emit someSignal(Type::ERR);
        	}
        
        signals:
        	void someSignal();
        	void someSignal(Type type);
        };
        
        class Container : public QWidget
        {
        	Q_OBJECT
        public:
        	Container(QWidget *parent = nullptr)
        	{
        		auto widget = new Widget;
        		connect(widget, qOverload<>(&Widget::someSignal),
        			this, qOverload<>(&Container::onSomeSignal));
        		connect(widget, qOverload<Widget::Type>(&Widget::someSignal),
        			this, qOverload<Widget::Type>(&Container::onSomeSignal));
        	}
        
        public slots:
        	void onSomeSignal() {}
        	void onSomeSignal(Widget::Type /* type */) {}
        };
        
        // main.cpp
        #include <QApplication>
        #include "header.h"
        int main(int argc, char **argv)
        {
        	QApplication app(argc, argv);
        
        	Container c;
        	c.show();
        
        	return QApplication::exec();
        }
        
        1 Reply Last reply
        0
        • dheerendraD Offline
          dheerendraD Offline
          dheerendra
          Moderators Qt Champions 2024 Qt Champions 2022 Qt Champions 2017
          wrote on last edited by
          #4

          Did you miss adding closing bracket for the first connect statement ?

          Dheerendra
          @Community Service
          Certified Qt Specialist
          https://www.pthinks.com

          U 1 Reply Last reply
          0
          • dheerendraD dheerendra

            Did you miss adding closing bracket for the first connect statement ?

            U Offline
            U Offline
            user4592357
            wrote on last edited by
            #5

            @dheerendra
            yes, i just noticed while copy-pasting the code to a small example.

            1 Reply Last reply
            0
            • dheerendraD Offline
              dheerendraD Offline
              dheerendra
              Moderators Qt Champions 2024 Qt Champions 2022 Qt Champions 2017
              wrote on last edited by
              #6

              Missing bracket was the issue.

              Dheerendra
              @Community Service
              Certified Qt Specialist
              https://www.pthinks.com

              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