Results 1 to 7 of 7

Thread: QLineEdit

  1. #1
    Join Date
    Oct 2007
    Posts
    78
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QLineEdit

    QLineEdits signal editingFinished() "This signal is emitted when the Return or Enter key is pressed or the line edit loses focus...."

    When clicking a QToolBar or QMenu in a QMainWindow it neither causes the current QLineEdit to lose focus or complete the edit.

    This has become a problem since the QToolBar action or Menu action could be dependent on the latest QLineEdit information. The textChanged() and the like signals creates corner cases of large CPU usage if a key is just mashed, spammed, etc and that is best avoided.

    My question is other then having the QActions emit a finish all edits signal on triggered() is there any other possible solutions?

    Bob

  2. #2
    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: QLineEdit

    Keyboard focus is not the same as window activation. Some platforms treat it as one, others don't. Qt follows the platform behaviour. Could you describe what exactly the problem is? Losing focus upon click? You can do that with an event filter on the application object...

  3. #3
    Join Date
    Oct 2007
    Posts
    78
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QLineEdit

    I don't think actual code will be of any value here so I will try quasi pseudo code in attempts to clarify the situation.

    I have a QLineEdit that transfers its text to a structure that is used to store the text in a file.

    It is transfered to the structure when the editingFinished() signal is emitted.

    Now in the QMainWindow I have a QAction (QToolBar and QMenu) so when I click on the "Save" QToolButton it does not cause the QLineEdit to lose focus (or finished the edit) so it saves the structure with the previous data. It never gets updated since editingFinished() never gets emitted.

    I am not sure how to go about making sure the QLineEdits most recent text is applied to the structure. In the QAction of the "save" button? In the QLineEdit (do not see what other signal could be valid)? Or some other QEvent processing that could force the editingFinished() signal.

    Bob

    EDIT: Ultimately clicking a QToolButton or a QMenu does not cause a QLineEdits editingFinished() signal to be emitted and thats the root of my problem.
    Last edited by coderbob; 27th February 2008 at 11:52.

  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: QLineEdit

    Quote Originally Posted by coderbob View Post
    Now in the QMainWindow I have a QAction (QToolBar and QMenu) so when I click on the "Save" QToolButton it does not cause the QLineEdit to lose focus (or finished the edit) so it saves the structure with the previous data. It never gets updated since editingFinished() never gets emitted.
    So why don't you submit the pending change to the structure yourself before saving? You can even check (using QLineEdit::modified) if the contents need saving.

  5. #5
    Join Date
    Oct 2007
    Posts
    78
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QLineEdit

    The QLineEdit could be any one of a number of lineEdits. I would have to track which one had focus and was currently being edited so the "save" function could be sure it had the most recent data.

    There are a few different ways to track which QLineEdit had focus at the time of the "save" call but all implement more overhead. I guess I am not really seeing an easy solution.

    Thank you for the suggestions Wysota.

    Bob

  6. #6
    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: QLineEdit

    Quote Originally Posted by coderbob View Post
    The QLineEdit could be any one of a number of lineEdits. I would have to track which one had focus and was currently being edited so the "save" function could be sure it had the most recent data.
    You don't have to track anything, you can ask the application for the widget that currently has focus and check if its one of your line edits. Or you can just iterate over all your lineedits and save any that is marked as modified.

  7. #7
    Join Date
    Oct 2007
    Posts
    78
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QLineEdit

    Lol you respond faster than I can edit my posts. I was looking at QApplication::focusWidget() and figured I could just force the update in the "save" function with that information.

    Bob

Similar Threads

  1. QLineEdit and focus
    By serega in forum Qt Programming
    Replies: 1
    Last Post: 16th January 2008, 00:49
  2. how to get last character of QLineEdit
    By yagabey in forum Qt Programming
    Replies: 1
    Last Post: 5th January 2008, 16:38
  3. closeEditor() not always closing QLineEdit
    By mclark in forum Qt Programming
    Replies: 8
    Last Post: 27th November 2007, 01:44
  4. Problem Euro Sign with QLineEdit
    By Kubil in forum Qt Programming
    Replies: 1
    Last Post: 24th August 2007, 04:56
  5. QValidator, regular expressions and QLineEdit
    By hvengel in forum Qt Programming
    Replies: 1
    Last Post: 8th August 2007, 01:25

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.