connecting overloaded signals to overloaded slots fails

  • 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.

  • Lifetime Qt Champion

    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.

  • 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
    	enum Type { ERR };
    		emit someSignal();
    		emit someSignal(Type::ERR);
    	void someSignal();
    	void someSignal(Type type);
    class Container : public QWidget
    	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;;
    	return QApplication::exec();

  • Qt Champions 2017

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

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

  • Qt Champions 2017

    Missing bracket was the issue.

Log in to reply