Reputation: 5420
I want to use QLineEdit to get an integer value that I want to work with. My problem is that I want to wait till the text is entered. It would also be nice if I can give a default text at the begining that will automatically be deleted after clicking on the QEditLine, like :
for the first point I tried this and it didn't work:
......
int num =0;
QLineEdit *qtest = new QLineEdit();
........
mailayout->addWiget(qtest);// when I use the while loop the QLineEdit won't be added !!
while(num ==0 ){
num = qtest->text.toInt();
}
.............
the program stays in the while loop, any Idea I'm doing wrong?
Upvotes: 1
Views: 887
Reputation: 22346
Use setPlaceholderTest(const QString&)
for text to show when the user has not entered anything.
Don't poll the QLineEdit
for changes, this is Qt so use signals.
connect( qtest, SIGNAL( editingFinished() ),
someContainerObj, SLOT( myLineEditSlot() ) );
...
ContainerObj::myLineEditSlot()
{
int num = qtest->text().toInt();
...
}
Upvotes: 6