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. [SOLVED] Slot without Q_OBJECT
QtWS25 Last Chance

[SOLVED] Slot without Q_OBJECT

Scheduled Pinned Locked Moved General and Desktop
slotsignalqobjecttemplate
3 Posts 3 Posters 3.0k 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.
  • Q Offline
    Q Offline
    qtacc32
    wrote on 28 May 2015, 15:40 last edited by qtacc32 6 Apr 2015, 17:20
    #1

    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
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 31 May 2015, 22:41 last edited by
      #2

      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
      1
      • J Offline
        J Offline
        JKSH
        Moderators
        wrote on 1 Jun 2015, 01:40 last edited by
        #3

        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
        1

        2/3

        31 May 2015, 22:41

        • Login

        • Login or register to search.
        2 out of 3
        • First post
          2/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved