Results 1 to 12 of 12

Thread: Tracing signals.

  1. #1
    Join Date
    Feb 2006
    Posts
    47
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Tracing signals.

    Hello,

    I am having trouble tracing signals and slots in my application. I have a function that is being called once a tree view has changed. It seems to be called three times however. I want to identify who is emitting the replicated signal so I can block them appropriately.

    How do I do this?

    I suppose this is a more general question about debugging signals/slots in Qt.

    John.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

  3. #3
    Join Date
    Feb 2006
    Posts
    47
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Tracing signals.

    I can use the signal spy you suggested, but can't help but to think that this should be solved by inspection.

    I suppose I am not fully aware of which signals are emitted when in my tree view. For example, I did not know that a signal is emitted when the color of a tree leaf is changed.

    J.

  4. #4
    Join Date
    Feb 2006
    Posts
    47
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Unhappy Re: Tracing signals.

    Are there a special way to configure Qt so that it can use the spy?

    #include <QSignalSpy>

    can't be found, and neither can <QTest>.

    how can I configure Qt to use the spy?

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Tracing signals.

    CONFIG += qtestlib

  6. #6
    Join Date
    Feb 2006
    Posts
    47
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Tracing signals.

    This worked, thank you.

    Now I have A QSignalSpy pointer in my class. I instantiated it:
    Qt Code:
    1. Signal_Spy = new SignalSpy(Acquisition_Browser->DICOM_Header_Tree,SIGNAL(itemChanged(QTreeWidgetItem*,int)) );
    To copy to clipboard, switch view to plain text mode 

    I simply do not know how to identify the signal's origin at this point....

    Qt Code:
    1. Signal_Spy->sender()->objectName();
    To copy to clipboard, switch view to plain text mode 

    was my first instinct in order to extract the name of the object whose signal was the trigger. "sender()" however, is protected. So how do I identify the signal's source?

    (This is very new to me!).


    J

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Tracing signals.

    Quote Originally Posted by johnny_sparx
    Now I have A QSignalSpy pointer in my class.
    I think that this signal spy will be more helpful.

    Quote Originally Posted by johnny_sparx
    Signal_Spy->sender()->objectName();
    You don't need a singnal spy for this --- just use sender() within your slot.

  8. #8
    Join Date
    Feb 2006
    Posts
    47
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Tracing signals.

    jacek, thanks alot - you seem to help me out alot on this forum...

    I am still questionning though. I was able to use sender directly as you proposed, and it identifies the object that emitted the signals. But I need to know which actions were performed in order to emit the signal to my slot.

    I am looking at itemChanged from QTreeView. Is it a setTextColor? is it a setData? I already know the object, but need more details.

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Tracing signals.

    Set a breakpoint in the slot and see the stack trace.

  10. #10
    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: Tracing signals.

    Quote Originally Posted by johnny_sparx
    I am looking at itemChanged from QTreeView. Is it a setTextColor? is it a setData? I already know the object, but need more details.
    setData(). setTextColor is just a setData wrapper defined as:

    Qt Code:
    1. inline void setTextColor(int column, const QColor &color)
    2. { setData(column, Qt::TextColorRole, color); }
    To copy to clipboard, switch view to plain text mode 

    Which is easy to guess by the way, as it has to be QTreeView method which emits the signal and only one that does allow an item to be changed (and emits a signal) is QAbstractItemModel::setData().

  11. #11
    Join Date
    Feb 2006
    Posts
    47
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Tracing signals.

    Okay.... now I have narrowed things down.... it IS the setColor that is emitting the signal. Weirdly, I have blocked the signals before I change the signals (see top and bottom of the function:

    Qt Code:
    1. #define BLOCK_SIGNALS blockSignals(TRUE)
    2. #define ALLOW_SIGNALS blockSignals(FALSE)
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void AcquisitionBrowserWidget::Read_Only_Checked(bool value)
    2. {
    3. BLOCK_SIGNALS;
    4. // Change the state of the 'Update Header' button appropriately.
    5. Acquisition_Browser->Update_Header_Button->setEnabled(!value);
    6. // If 'Read only' checkbox is not checked (edit possible), then the
    7. // editable fields should be dark green otherwise, it should be black.
    8. if(!value)
    9. {
    10. // Change the color of the editable fields to green.
    11. DICOM_Information__Patient_Information__Name->setTextColor(1,QColor(Qt::darkGreen));
    12. DICOM_Information__Patient_Information__ID->setTextColor(1,Qt::darkGreen);
    13. DICOM_Information__Study__Description->setTextColor(1,Qt::darkGreen);
    14. DICOM_Information__Study__UID->setTextColor(1,Qt::darkGreen);
    15. DICOM_Information__Series__Description->setTextColor(1,Qt::darkGreen);
    16. DICOM_Information__Series__UID->setTextColor(1,Qt::darkGreen);
    17.  
    18. // Set the fields so that they are not editable.
    19. DICOM_Information__Patient_Information__Name->setFlags(Qt::ItemIsEditable);
    20. DICOM_Information__Patient_Information__ID->setFlags(Qt::ItemIsEditable);
    21. //DICOM_Information__Study__Description->setFlags(Qt::ItemIsEditable);
    22. DICOM_Information__Study__UID->setFlags(Qt::ItemIsEditable);
    23. //DICOM_Information__Series__Description->setFlags(Qt::ItemIsEditable);
    24. DICOM_Information__Series__UID->setFlags(Qt::ItemIsEditable);
    25.  
    26. Acquisition_Browser->Update_Header_Button->setIcon(QIcon("greenball.png"));
    27. DICOM_Tree_Data_Changed = false;
    28. DICOM_Tree_Data_Updated = false;
    29. }
    30. else
    31. {
    32. // Change the color of the editable fields to black.
    33. DICOM_Information__Patient_Information__Name->setTextColor(1,QColor(Qt::black));
    34. DICOM_Information__Patient_Information__ID->setTextColor(1,Qt::black);
    35. DICOM_Information__Study__Description->setTextColor(1,Qt::black);
    36. DICOM_Information__Study__UID->setTextColor(1,Qt::black);
    37. DICOM_Information__Series__Description->setTextColor(1,Qt::black);
    38. DICOM_Information__Series__UID->setTextColor(1,Qt::black);
    39.  
    40. // Set the fields so that they are not editable.
    41. DICOM_Information__Patient_Information__Name->setFlags(!Qt::ItemIsEditable);
    42. DICOM_Information__Patient_Information__ID->setFlags(!Qt::ItemIsEditable);
    43. DICOM_Information__Study__UID->setFlags(!Qt::ItemIsEditable);
    44. DICOM_Information__Series__UID->setFlags(!Qt::ItemIsEditable);
    45.  
    46. // If the data changed, then notify the user.
    47. if(DICOM_Tree_Data_Updated && DICOM_Tree_Data_Changed)
    48. {
    49. QMessageBox::information(this,"DICOM Inspector Warning","The DICOM information has changed but was not updated.");
    50. }
    51. // Update the colored indicator on the button.
    52. ALLOW_SIGNALS;
    53. }
    To copy to clipboard, switch view to plain text mode 


    Have I done this incorrectly? It seems like the color change is the trigger for my problems.

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Tracing signals.

    You have blocked signals only for AcquisitionBrowserWidget.

Similar Threads

  1. Signals are delayed on X11?
    By Cruz in forum Qt Programming
    Replies: 13
    Last Post: 18th February 2009, 12:59
  2. Signals and Slots
    By 83.manish in forum Qt Programming
    Replies: 3
    Last Post: 30th June 2008, 10:31
  3. Problem with SpinBox signals and slots
    By ramstormrage in forum Newbie
    Replies: 4
    Last Post: 2nd May 2008, 01:45
  4. QThread and signals (linux/UNIX signals not Qt Signals)
    By Micawber in forum Qt Programming
    Replies: 1
    Last Post: 28th November 2007, 22:18
  5. KDE Signals
    By chombium in forum KDE Forum
    Replies: 1
    Last Post: 25th January 2006, 18:45

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.