Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    [SOLVED] Slot without Q_OBJECT

    General and Desktop
    slot signal qobject template
    3
    3
    2603
    Loading More Posts
    • 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.
    • Q
      qtacc32 last edited by qtacc32

      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?)?

      Thanks!

      // EDIT:

      I just realized that this works:

      template<class T>
      class Test2 : public QObject
      {
      	T t = 3;
      public:
      	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 ...

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi,

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

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 1
        • JKSH
          JKSH Moderators last edited by

          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

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          1 Reply Last reply Reply Quote 1
          • First post
            Last post