View Full Version : Last edited item
haldrik
13th May 2012, 04:36
Hi, I have a form with many fields, and a findButton, I need make something for identify the last lineEdit edited when I press the findButton. This is for find matches on costumerId, costumerName, or costumerAddress, etc, without have to use a combobox with the possible search fields. Just clic on the lineEdit that you interested, type the string and clic on findButton.
Here a video :)
http://www.youtube.com/watch?v=HywE8RdQg6M
AlexSudnik
13th May 2012, 06:02
One of the ways is to store all of the editable QLineEdit objects' pointers in an index-based table ( hash for instance ) and use its' ids with a signal mapper.
Also , you'll probably want to use a distinct const pointer that will store this last edited QLineEdit : const QLineEdit* lastEditedField and a private slot void updateLastEditedField( ) connected with a signal mapper (which is connected with a void textChanged ( const QString & text ) signal of those QLineEdit objects ) , this way you'll get a caller's id to retrieve a pointer and set it as a "lastEditedField".
You can also do it withought any mapping involved , but in this case you'll have to use QObject* QObject::sender () const , but since you'll lose an object's type , you'll also have to make some casts , which i think is not smart:).
amleto
13th May 2012, 11:03
I would say that the find button should take into consideration ALL of the data filled in on the form.
In any case, the form could provide a slot that gives the search data, e.g. a map of field name to string data QMap<QString, QString>.
// form with line edits cpp
void lineeditform::slotGiveSearchData(QMap<QString, QString>& data)
{
// grab data from ui and put in map
}
//results.hpp - your widget with find button and search results
class results : QWidget
{
Q_OBJECT
...
private slots:
void slotFind();
signals:
signalGetSearchData();
};
// results form cpp
results::results(...)
{
// connect find button clicked() to slotFind() slot
// connect signalGetSearchData to slotGiveSearchData on lineedit form
}
void results::slotFind()
{
QMap<QString, QString> searchData;
// use signal signalGetSearchData
emit signalGetSearchData(searchData);
// we now have the data.
// Do your search...
}
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.