Results 1 to 2 of 2

Thread: templated signal or slot

  1. #1
    Join Date
    Jul 2007
    Posts
    121
    Thanks
    38
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default templated signal or slot

    Moc returns error when slot is declared as a templated function.
    I have following situation - my slots are different only in return type. So, following examples of MDI in QT docs I am creating two functions per each action. Example:

    void newView(); // slot that is triggered by a menu action
    View* createView(); // actual creation of a View.

    If I have, say 10 of such different view types, the code becomes too cluttered. I don't want to move "creatView" code in "newView", since "createVeiw" calls will be reused elsewhere.

    Question: is there a possibility to somehow employ templates here and do not revert to doing something like:
    void newView(int viewtype)
    {
    switch (viewtype)
    {
    BaseView* view;
    case 1: view = (BaseView*) createView1();
    case 2: view = (BaseView*) createView2();
    ...
    }
    }

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: templated signal or slot

    No, you cannot.
    See this link: http://doc.trolltech.com/4.3/templates.html.

    The current method seems pretty good to me.
    How would you have done it with template functions?

    Would you have had a single createView function parameterized by what?
    If you can create 10 views with the same template function, then doesn't that mean that all functions createView1..10 are similar? Therefore you could pass viewType to createView.

    Regards

  3. The following user says thank you to marcel for this useful post:

    QPlace (4th August 2007)

Similar Threads

  1. Signal and slots
    By villy in forum Qt Programming
    Replies: 1
    Last Post: 12th January 2007, 10:10
  2. signal slot connection
    By Big Duck in forum Newbie
    Replies: 2
    Last Post: 4th July 2006, 13:31
  3. signal not getting communicated to slot
    By quickNitin in forum Qt Programming
    Replies: 17
    Last Post: 2nd June 2006, 04:56
  4. Manually send signal to slot
    By donmorr in forum Qt Programming
    Replies: 1
    Last Post: 29th May 2006, 15:03
  5. signal slot conection using a string, not a SLOT
    By rianquinn in forum Qt Programming
    Replies: 6
    Last Post: 5th February 2006, 18:52

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.