Results 1 to 5 of 5

Thread: QObject::blockSignals(true) not blocking QTextEdit->textChanged() signal

  1. #1
    Join Date
    Nov 2015
    Location
    Vermont
    Posts
    52
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Question QObject::blockSignals(true) not blocking QTextEdit->textChanged() signal

    I have a bunch of UI objects with their signals connected to a `registerChange()` slot. I do not want this slot to be triggered when I am initially populating the existing data, so I use `blockSignals()`. This works great for everything except the QTextEdit object, which still successfully triggers `registerChange()`. Any idea why this would be? If my understanding of `blockSignals` is correct then this shouldn't be possible. Stripped down code for context:
    Qt Code:
    1. ContactWindow::ContactWindow()
    2. {
    3. ...
    4. connect(ui->first_name_edit, SIGNAL(textEdited(QString)), this, SLOT(registerChange()));
    5. connect(ui->last_name_edit, SIGNAL(textEdited(QString)), this, SLOT(registerChange()));
    6. connect(ui->email_edit, SIGNAL(textEdited(QString)), this, SLOT(registerChange()));
    7. connect(ui->notes_edit, SIGNAL(textChanged()), this, SLOT(registerChange()));
    8. ...
    9. }
    10.  
    11. void ContactWindow::populateData()
    12. {
    13. // Block signals while setting
    14. this->blockSignals(true);
    15.  
    16. // Populate UI fields
    17. ui->first_name_edit->setText(current_contact.first_name);
    18. ui->last_name_edit->setText(current_contact.last_name);
    19. ui->email_edit->setText(current_contact.email);
    20. ui->notes_edit->setText(current_contact.notes); // This signal still gets caught.
    21.  
    22. // Unblock signals
    23. this->blockSignals(false);
    24. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    507
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QObject::blockSignals(true) not blocking QTextEdit->textChanged() signal

    Hi, the docs say
    If block is true, signals emitted by this object are blocked
    so I think you need to set it for "ui->notes_edit" and not for "this".

    Ginsengelf

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

    ce_nort (29th January 2024)

  4. #3
    Join Date
    Nov 2015
    Location
    Vermont
    Posts
    52
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: QObject::blockSignals(true) not blocking QTextEdit->textChanged() signal

    Quote Originally Posted by Ginsengelf View Post
    Hi, the docs say

    so I think you need to set it for "ui->notes_edit" and not for "this".

    Ginsengelf
    Okay, that does make sense, but then why does it work for every other UI element?

  5. #4
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    507
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QObject::blockSignals(true) not blocking QTextEdit->textChanged() signal

    Hi, I was wondering about that myself when I wrote the answer. No idea.

    Ginsengelf

  6. The following user says thank you to Ginsengelf for this useful post:

    ce_nort (29th January 2024)

  7. #5
    Join Date
    Nov 2015
    Location
    Vermont
    Posts
    52
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: QObject::blockSignals(true) not blocking QTextEdit->textChanged() signal

    Huh, I guess some things will remain mysterious. Thanks for your help!

Similar Threads

  1. C++/Qt4 - QTextEdit - textChanged slot - Question
    By jimbo in forum Qt Programming
    Replies: 0
    Last Post: 18th March 2015, 13:02
  2. Replies: 4
    Last Post: 19th June 2012, 00:25
  3. QTextEdit's textChanged() signal
    By bangqianchen in forum Qt Programming
    Replies: 1
    Last Post: 11th January 2010, 10:11
  4. QTextEdit, Highlighting and textChanged()
    By onamatic in forum Qt Programming
    Replies: 2
    Last Post: 12th November 2008, 11:44
  5. textChanged signal issue
    By chaosgeorge in forum Qt Programming
    Replies: 3
    Last Post: 9th November 2006, 00:32

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.