[SOLVED] Slot without Q_OBJECT

  • Hello,

    I'd like to have a template class but unfortunately, it doesn't work with Q_OBJECT.
    So I read about Q_INVOKABLE which would work I guess but be quite inconvenient.
    I could connect signals to lambdas though and call the invokable methods from there.

    My question: Why does Qt allow connecting to lambdas but not to non-QObject classes (which lambdas are too, not?)?


    // EDIT:

    I just realized that this works:

    template<class T>
    class Test2 : public QObject
    	T t = 3;
    	void SltX()
    		std::cout << "Test2::SltX: " << t << std::endl;
    QObject::connect(&mainWindow, &MainWindow::SigTest, &t2, &Test2<int>::SltX);

    I guess I can live with the downsides of not having Q_OBJECT (is there a complete list with all of them?).

    // EDIT2:

    Ou, cannot have signals :-/
    Damn, will templates ever be supported? So important ...

  • Lifetime Qt Champion


    Here you can find the reason about why there's that limitation with templates

  • Moderators

    Qt developers have investigated this before, and there is a partially-working patch.

    There are still a number of important challenges to work through, but devs are focussing on other things at the moment. It is not currently being actively worked on: http://comments.gmane.org/gmane.comp.lib.qt.devel/10327

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.