Results 1 to 8 of 8

Thread: QSignalMapper One single Object

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: QSignalMapper One single Object

    What exactly do you mean by "track signals"?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    Default Re: QSignalMapper One single Object

    Anyway, try this:
    Qt Code:
    1. #include <QtGui>
    2.  
    3.  
    4. class SignalTracker : public QObject {
    5. int qt_metacall(QMetaObject::Call call, int id, void **args) {
    6. id = QObject::qt_metacall(call, id, args);
    7. if(id==-1 || call != QMetaObject::InvokeMetaMethod)
    8. return id;
    9. if(!m_slots.contains(id)) return -1;
    10. Signal sig = m_slots.value(id);
    11. qDebug() << "Object:" << sig.source->objectName() << "signal:" << sig.signal;
    12. return -1;
    13. }
    14. public:
    15. SignalTracker(QObject *parent = 0) : QObject(parent) {
    16. m_slotId = 0;
    17. }
    18. bool connectSignal(QObject *obj, const char *signal) {
    19. QByteArray theSignal = QMetaObject::normalizedSignature(signal);
    20. int signalId = obj->metaObject()->indexOfSignal(theSignal);
    21. if(signalId == -1) {
    22. return false;
    23. }
    24. m_slots[++m_slotId] = Signal(obj, theSignal);
    25. QMetaObject::connect(obj, signalId, this, QObject::metaObject()->methodCount()+m_slotId);
    26. return true;
    27. }
    28. private:
    29. int m_slotId;
    30. struct Signal {
    31. QObject *source;
    32. QByteArray signal;
    33. Signal(QObject *src, const QByteArray &ba) : source(src), signal(ba){}
    34. Signal() : source(0){}
    35. };
    36. QHash<int,Signal> m_slots;
    37. };
    38.  
    39. int main(int argc, char **argv){
    40. QApplication app(argc, argv);
    41. SignalTracker tracker;
    42. QPushButton button("Click me");
    43. button.setObjectName("some button");
    44. tracker.connectSignal(&button, "clicked()");
    45. button.show();
    46. le.setObjectName("some line edit");
    47. tracker.connectSignal(&le, "textChanged(const QString &)");
    48. le.show();
    49. return app.exec();
    50. };
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    May 2009
    Posts
    56
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    6

    Default Re: QSignalMapper One single Object

    Quote Originally Posted by wysota View Post
    What exactly do you mean by "track signals"?
    Hi wysota,
    what i meanby that is: know when different signal from different or the same object have been triggered to count then or to wait for all of then before doing something, i have no tried yet the example. i let you know when i have.

    Thanks for the help.

  4. #4
    Join Date
    Jan 2008
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Re: QSignalMapper One single Object

    I've just made a class doing this. It tracks every signals from the object you want to monitor. You can just test the parameter of the emitted (or emittedNameOnly) signal to check only the ones you want.

Similar Threads

  1. QSignalMapper
    By axisdj in forum Newbie
    Replies: 6
    Last Post: 16th September 2010, 02:52
  2. QSignalMapper and argument problems
    By harmodrew in forum Newbie
    Replies: 14
    Last Post: 7th August 2010, 20:20
  3. help with QSignalMapper and actions
    By andreime in forum Newbie
    Replies: 1
    Last Post: 9th August 2009, 19:24
  4. ? about QSignalMapper
    By JimDaniel in forum Qt Programming
    Replies: 1
    Last Post: 13th January 2008, 22:21
  5. QSignalMapper question: SIGNAL 2 int's
    By vonCZ in forum Newbie
    Replies: 5
    Last Post: 20th July 2007, 11:02

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.