Results 1 to 4 of 4

Thread: Catching all Signals from widget in QTest

  1. #1
    Join Date
    Oct 2011
    Posts
    51
    Thanks
    5
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Catching all Signals from widget in QTest

    Hi!

    I need to catch all signals emitted from a widget using QSignalSpy (or something else), is there a way to do that? It can by only number of those signals without any other info.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Catching all Signals from widget in QTest

    You can list all signals of a type by iterating over the methods of its QMetaObject and checking for QMetaMethods for signals.

    You could then create a list of signal spys, each connected to one signal, or connect all signals to a custom slot in a receiver object.

    Cheers,
    _

  3. #3
    Join Date
    Oct 2011
    Posts
    51
    Thanks
    5
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Catching all Signals from widget in QTest

    If somebody want to know how to do that I paste my code.

    Qt Code:
    1. #include <QSignalSpy>
    2.  
    3. class QAllSignalSpy : public QList<QSignalSpy*>
    4. {
    5.  
    6. public:
    7. explicit QAllSignalSpy(QObject *parent){
    8. QObject *object = parent;
    9. const QMetaObject *me = object->metaObject();
    10. int metaCount = me->methodCount();
    11. for(int i = 0;i<metaCount;i++){
    12. QMetaMethod mm = me->method(i);
    13. if (mm.methodType() == QMetaMethod::Signal){
    14. QString method = QString::number(2)+ mm.methodSignature().constData();
    15. this->append( new QSignalSpy(object, method.toLatin1().constData() ) );
    16. }
    17. }
    18. }
    19.  
    20. int signalCount(){
    21. int all = 0;
    22. for(int i=0;i<this->size(); i++)
    23. all += this->at(i)->count();
    24. return all;
    25. }
    26. };
    To copy to clipboard, switch view to plain text mode 

    enjoy!

  4. The following user says thank you to cszawisza for this useful post:

    MarPan (14th April 2015)

  5. #4
    Join Date
    May 2013
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows
    Wiki edits
    2

    Lightbulb Re: Catching all Signals from widget in QTest

    I have just published a tiny header-only library which does exactly this: QSignalInspector

Similar Threads

  1. [Qt Widget + libvlc] catching mouse events
    By mentalmushroom in forum Qt Programming
    Replies: 9
    Last Post: 6th March 2012, 14:39
  2. Indicating/catching signals
    By Tomasz in forum Newbie
    Replies: 5
    Last Post: 30th September 2010, 14:24
  3. emitting and catching signals
    By srohit24 in forum Qt Programming
    Replies: 12
    Last Post: 4th August 2009, 19:32
  4. How do I block the signals emited by a widget
    By chikkireddi in forum Qt Programming
    Replies: 1
    Last Post: 11th January 2008, 14:11
  5. QThread and signals (linux/UNIX signals not Qt Signals)
    By Micawber in forum Qt Programming
    Replies: 1
    Last Post: 28th November 2007, 23:18

Tags for this Thread

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.