how to get the text from a LineEdit using QT??
I want to display the text in the LineEdit using Qt.
but when i use the code an empty string wiil be displayed.
The following is my code.
Code:
{// it's a "QPushButton", do something with pb here
popup1->setWindowTitle("Rename the folder");
connect( lb, SIGNAL( returnPressed() ), lb, SLOT( hide() ) );
lb->setFocus();
lb->show();
qDebug()<<lb->text();
button->setText(lb->text());
button->setObjectName(lb->text());
} }
Can any one help me.
Thanks in advance.
Re: how to get the text from a LineEdit using QT??
Code:
{// it's a "QPushButton", do something with pb here
popup1->setWindowTitle("Rename the folder");
connect( lb, SIGNAL( returnPressed() ), lb, SLOT( hide() ) );
lb->setFocus();
lb->show();
qDebug()<<lb->text();
button->setText(lb->text());
button->setObjectName(lb->text());
} }
u are not setting any text in QLineEdit in ur code .
u shuld use
Code:
lb->setText("Ur Text that u want to display");
or else while constructing the lineEdit
QLineEdit::QLineEdit ( const QString & contents, QWidget * parent = 0 )u can set
Re: how to get the text from a LineEdit using QT??
Actually the text is entered at run time.
Whatever is entering at runtime, that should be displayed using text() and set as the text of the button.
Re: how to get the text from a LineEdit using QT??
Sure, but your code just reads the initial text, which in your snippet, is empty.
You create a line edit and read its content, which if course is unchanged since there has been no possibility for any user interaction.
What you probably want is to show the input window and set the button once there the user has entered some text.
Connect a slot to editingFinished() or returnPressed() and read the text in there.
Cheers,
_
Re: how to get the text from a LineEdit using QT??
Quote:
Originally Posted by
Soumya Somasekhar Ram
Actually the text is entered at run time.
Whatever is entering at runtime, that should be displayed using text() and set as the text of the button.
u need to connect the signal of lineEdit to a slot which will update the text of QPushButton
Code:
connect( lb,
SIGNAL( textChanged
(const QString &) ), lb,
SLOT( changeButtonText
(const QString &) ) );
slot:
Code:
changeButtonText
(const QString &data
){
button->setText(data);
}
as u used returnPressed() , remove the hide() slot
and add ur changeButtonText()
Code:
connect( lb, SIGNAL( returnPressed ( ), lb, SLOT( changeButtonText() ) )
and in
Code:
changeButtonText()
{
button->setText(lb->text());
}
Re: how to get the text from a LineEdit using QT??
Just to clarify what wagmare wrote: those are two options, both will result in the line edit's text on the button.
The first option will update the button text as the user types, the second one will update it only at the end.
Either option can keep the connect to hide() though.
Cheers,
_
Re: how to get the text from a LineEdit using QT??
That code didn't work.
Actually its because of the object name of the dynamically created push button won't available using the following code.
QPushButton *button = (QPushButton *)sender()
Can u suggest any other way to get the reference of that particular button ,when user clicks on it.
Thank you for your response.
Re: how to get the text from a LineEdit using QT??
Rule of thumb: if you need to access a widget after construction, keep its pointer in a member variable of your class :)
Cheers,
_
Re: how to get the text from a LineEdit using QT??
But the problem is ,here I am creating alarge no of pushButtons dynamically.
I have to identify which one is currently selected.
Is there any other method for checking the active widget?
QObject::sender() return the refference of the main window.
Can any one help me.
Thanks in advance.
Re: how to get the text from a LineEdit using QT??
Quote:
Originally Posted by
Soumya Somasekhar Ram
But the problem is ,here I am creating alarge no of pushButtons dynamically.
Ah, you didn't say that.
Look at QButtonGroup or alternatively for QSignalMapper
Cheers,
_
Re: how to get the text from a LineEdit using QT??
In the above reply of Mr.Wagmare, where should I define the functions changeButtonText(const QString &data) and changeButtonText().
I defined it as
void Mainwindow::changeButtonText(const QString &data)
{
}
Then ,it shows a run time error that no such slot for lb(label name here).
Re: how to get the text from a LineEdit using QT??
Well, obviously you need to use the pointer of the main window instance as the receiver object in the connect statement.
e.g. "this" if you do the connect from inside a main window method
Cheers,
_