Results 1 to 5 of 5

Thread: Need a signal almost like editingFinished

  1. #1
    Join Date
    Sep 2010
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Need a signal almost like editingFinished

    Looking at the signals available from QLineEdit for triggering something to happen when the text changes there are the following.

    void editingFinished ()
    void textChanged ( const QString & text )
    void textEdited ( const QString & text )

    I need to connect to a signal that is only emitted when the editing is actually finished, not as each character is entered. For this, editingFinished() works. My problem right now is that editingFinished() also gets called when a user tab's through the line edit gaining and then losing focus. I don't want my slot to be called unless the text actually changed.

    What do I need to do to make this happen? Do I need to subclass QLineEdit, do I need to override some event handlers?
    I'm pretty lost right now. I hope it'll be simple.

    Thanks,
    ~Eric

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Need a signal almost like editingFinished

    One way is to subclass QLineEdit.
    Another way, which I think in this case is better suited, is to do the logic on your side.
    This means, you connect both to textEdited() and editingFinished() - and in the receiving slots, you flag a bool (m_bTextEdited and m_bEditingFinished respectively).
    In your current slot which is now being called on editigFinished() you examine the two booleans, and execute the code in the slot only if both are true.
    Don't forget to reset the flags when you are done.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Sep 2010
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Need a signal almost like editingFinished

    Quote Originally Posted by high_flyer View Post
    One way is to subclass QLineEdit.
    Another way, which I think in this case is better suited, is to do the logic on your side.
    This means, you connect both to textEdited() and editingFinished() - and in the receiving slots, you flag a bool (m_bTextEdited and m_bEditingFinished respectively).
    In your current slot which is now being called on editigFinished() you examine the two booleans, and execute the code in the slot only if both are true.
    Don't forget to reset the flags when you are done.
    Thanks a bunch, that worked like a charm. Only needed one boolean though for the textEdited since my code was already attached to editingFinished the editingFinished boolean would always be true anyway.

    Edit:
    Out of curiosity, what was your m_b supposed to stand for?

  4. #4
    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: Need a signal almost like editingFinished

    There is also the QLineEdit::modified property that you can use. You can reimplement focusInEvent and focusOutEvent and clear the flag on focus in and check the flag on focus out and emit a signal. Or you can use modified directly with editingFinished() if it suits your needs.
    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.


  5. #5
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Need a signal almost like editingFinished

    Out of curiosity, what was your m_b supposed to stand for?
    This is the Hungarian notation.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. QComboBox editingFinished
    By aekilic in forum Qt Programming
    Replies: 6
    Last Post: 28th November 2020, 08:17
  2. dateEdit, editingFinished, isolate return key press
    By meena in forum Qt Programming
    Replies: 5
    Last Post: 1st July 2010, 06:32
  3. editingFinished of QLineEdit
    By weixj2003ld in forum Qt Programming
    Replies: 1
    Last Post: 3rd November 2009, 09:06
  4. QDialog, editingFinished, and Cancel Button.
    By jeffpogo in forum Qt Programming
    Replies: 8
    Last Post: 3rd June 2009, 03:22
  5. editingFinished() signal
    By jamadagni in forum Qt Programming
    Replies: 3
    Last Post: 17th February 2006, 05:39

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.