PDA

View Full Version : QLineEdit



coderbob
27th February 2008, 10:54
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

wysota
27th February 2008, 11:00
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...

coderbob
27th February 2008, 11:47
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.

wysota
27th February 2008, 11:56
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.

coderbob
27th February 2008, 12:10
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

wysota
27th February 2008, 12:20
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.

coderbob
27th February 2008, 12:27
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