[SOLVED] Add QLabel and QLineEdit from formLayout to QHash
-
Hello,
I have a FormLayout, with several rows which have one Label and one QLineEdit created like this:
@
for(int i=0; i<class.count(); i++)
{
lineEdit = new QLineEdit;
label = new QLabel;
label->setText(class->getName(i));
formLayout->addRow(label, lineEdit);
}
@I want to get the added content on the lineEdit with its label to a QHashTable. I've already tried some things like using textEdited but there I can only get the content of the lineEdit. With other things like editingFinished I cannot even get that.
I'm really stuck so any help would be appreciated!!!
Thanks in advance!
-
Hope it is QHash data structure. You need to work with signals QLineEdit.
@connect(lineEdit,SIGNAL(returnPressed()),&w,SLOT(callme()));
void callme(...)
{
QString text = lineEdit.text();hash.insert(label.text(),text())
}@
This should help you.
-
Hi! Thanks!!
I finally managed to do it but in another way, because the problem I see with your solution (I think) is that I would only get the last label. I did it like this:@
for(int i=0; i<class.count(); i++)
{
lineEdit = new QLineEdit;
lineEdit->setAccessibleName(class->get->Name(i));
label = new QLabel;
label->setText(class->getName(i));
formLayout->addRow(label, lineEdit);connect(lineEdit, SIGNAL(textEdited(QString)),
this, SLOT(addHash(QString)));
}
@And the slot would look like this:
@
void addHash(QString text)
{
QLineEdit edit = qobject_cast<QLineEdit>(sender());
hash.insert(edit->accessibleName(), text);
}
@The key to it is the sender function which I didnt know it existed.
Thank you!