Results 1 to 6 of 6

Thread: trouble with signals and slots

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: trouble with signals and slots

    Qt Code:
    1. QObject::connect(setbutton,SIGNAL(clicked()),num,SLOT(set(int nn, int nd)));
    To copy to clipboard, switch view to plain text mode 
    This is not legal in Qt. The slot should have less than or equal number of arguments as signal.

    Qt Code:
    1. Fraction add(const Fraction& other);
    2. Fraction subtract(const Fraction& other);
    3. Fraction multiply(const Fraction& other);
    4. Fraction divide(const Fraction& other);
    To copy to clipboard, switch view to plain text mode 
    All these function declaration are not possible int Qt, because Fraction is derived QObject, instead use somthing like
    Qt Code:
    1. void add(const Fraction& other);
    2. void subtract(const Fraction& other);
    3. void multiply(const Fraction& other);
    4. void divide(const Fraction& other);
    To copy to clipboard, switch view to plain text mode 

    Also typically all QObject derived class objects follow parent-child relationships, i.e the parent is passed during QObject construction. The best way to define Fraction class would be to (If you have decided to make it QObject)
    Qt Code:
    1. class Fraction: public QObject {
    2. Q_OBJECT
    3. public:
    4. Fraction(int nn, int nd, QObject * parent = 0);
    5. }
    To copy to clipboard, switch view to plain text mode 
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  2. The following user says thank you to Santosh Reddy for this useful post:


Similar Threads

  1. QT SIGNALS and SLOTS
    By beginQT in forum Newbie
    Replies: 7
    Last Post: 23rd September 2011, 14:40
  2. Signals & Slots!
    By qtoptus in forum Qt Programming
    Replies: 2
    Last Post: 15th April 2010, 01:50
  3. about signals and slots
    By Sandip in forum Qt Programming
    Replies: 9
    Last Post: 15th July 2008, 16:02
  4. help with signals and slots
    By superutsav in forum Qt Programming
    Replies: 3
    Last Post: 4th May 2006, 12:49
  5. trouble with signals and slots
    By therealjag in forum Newbie
    Replies: 4
    Last Post: 23rd February 2006, 21: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
  •  
Qt is a trademark of The Qt Company.