Results 1 to 2 of 2

Thread: can a single statement work in signal/slot mechanism

  1. #1
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default can a single statement work in signal/slot mechanism

    hi..
    i was just guessing that if there is any mechanism available in qt through which single signal can emit different slots just with a single statement..
    Qt Code:
    1. connect(navigate,SIGNAL(recordClicked()),navigate,SLOT(disableRecordButton()));
    2. connect(navigate,SIGNAL(recordClicked()),progress,SLOT(startProgress()));
    To copy to clipboard, switch view to plain text mode 
    can this work be done by single statement

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: can a single statement work in signal/slot mechanism

    Well... Yes, if you implement a function such as the following:

    Qt Code:
    1. QList<bool> multiconnect(QObject *sender, const char *sign, const QList<QObject*> &rcvs, const QList<const char*> &slts){
    2. if(rcvs.size()!=slts.size())
    3. return QList<bool>();
    4. QList<bool> results;
    5. for(int i=0;i<rcvs.size();i++){
    6. results << connect(sender, sign, rcvs[i], slts[i]);
    7. }
    8. return results;
    9. }
    To copy to clipboard, switch view to plain text mode 

    Then you should be able to call it as:
    Qt Code:
    1. QList<QObject *> rcvs;
    2. QList<const char *> slts;
    3. rcvs << myObj1 << myObj2 << myObj3;
    4. slts << SLOT(react()) << SLOT(doSomething()) << SLOT(doSomethingElse());
    5. QList<bool> result = multiconnect(this, SIGNAL(clicked()), rcvs, slts);
    6. if(result.isEmpty())
    7. qDebug() << "Bad args count";
    8. else if(result[2]==false)
    9. qDebug() << "SLOT myObj3::doSomethingElse() didn't connect";
    To copy to clipboard, switch view to plain text mode 

    Of course this can be shortened to a single statement:
    Qt Code:
    1. multiconnect(this, SIGNAL(clicked()), QList<QObject*>() << myObj1 << myObj2, QList<const char*>() << SLOT("xyz()") << SLOT("abc"));
    To copy to clipboard, switch view to plain text mode 

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

    salmanmanekia (8th August 2008)

Similar Threads

  1. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 07:13

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.