Results 1 to 5 of 5

Thread: Is there any way to pass default parameters values to any slot?

  1. #1
    Join Date
    Apr 2009
    Posts
    132
    Thanks
    67
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Red face Is there any way to pass default parameters values to any slot?

    Hi all!

    Is there any way to pass default parameters values to any slot?

    I read over there something baout adding an "=", but doesn't work
    connect(ui.actionZoom_1X, SIGNAL(triggered()), d, SLOT(UpdateCameraZoom(=1.0)));

    Any idea?

    Thanks in advance.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Is there any way to pass default parameters values to any slot?

    Qt Code:
    1. class Foo
    2. {
    3. public slots:
    4. void UpdateCameraZoom(qreal level = 1.0);
    5. };
    6.  
    7. void Foo::UpdateCameraZoom(qreal level)
    8. {
    9. // ...
    10. }
    11.  
    12. connect(ui.actionZoom_1X, SIGNAL(triggered()), d, SLOT(UpdateCameraZoom()));
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  3. #3
    Join Date
    Apr 2009
    Posts
    132
    Thanks
    67
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Is there any way to pass default parameters values to any slot?

    Oh my god! I didn't realise I could do that. Works perfectly for me. Thanks

    But let's say different default parameters with differente signals calling the same slot. How would you do it?

    Thanks.

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Is there any way to pass default parameters values to any slot?

    Quote Originally Posted by ricardo View Post
    But let's say different default parameters with differente signals calling the same slot. How would you do it?
    You could use for example QSignalMapper, QObject::sender() or QButtonGroup to map/identify the sender.
    J-P Nurmi

  5. #5
    Join Date
    Mar 2007
    Location
    Germany
    Posts
    229
    Thanks
    2
    Thanked 29 Times in 28 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Is there any way to pass default parameters values to any slot?

    It should be added that the kind of method declaration jpn presented is a feature of C++ and can be used for all kind of methods in C++. No matter if the method is a Qt slot or just a totally normal method of a simple class.

  6. The following user says thank you to Boron for this useful post:

    ricardo (5th May 2009)

Similar Threads

  1. Replies: 3
    Last Post: 3rd May 2009, 14:15
  2. How to pass values in 1 form to another
    By maveric in forum Newbie
    Replies: 4
    Last Post: 5th June 2008, 07:18
  3. default parameters in constructor class
    By mickey in forum General Programming
    Replies: 4
    Last Post: 23rd February 2008, 18:44
  4. Replies: 2
    Last Post: 16th August 2007, 00:20
  5. C++ and default values for functions
    By guestgulkan in forum General Programming
    Replies: 4
    Last Post: 2nd January 2007, 22:53

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.