PDA

View Full Version : Inputting values to GUI



gsabhishek
18th February 2015, 14:01
I am using a line edit on my gui...I need to get the values entered on the text field when i press go....thats not happening...everything goes fine if i hard code those values...please help!!

void MainWindow::on_pushButton_clicked()
{



QLineEdit lineEdit;
QLineEdit lineEdit_2;
QLineEdit lineEdit_3;



int n=lineEdit.text().toInt();
int rows=lineEdit_2.text().toInt();
int columns=lineEdit_3.text().toInt();
qDebug()<<n;



its showing n as '0'...I have not even initialised n..

Radek
18th February 2015, 15:28
If you have written something like your code snippet then the line edits are local in on_pushButton_clicked() and, most likely, shadowing the "right ones" line edits. You are entering values in the "right ones" line edits but the local ones are left empty. That's why you are getting nulls.
(1) see the output of the line edits as QStrings (remove toInt()). Are the strings empty? Do they contain what they should?
(2) see the result of the toInt() (do not default the first toInt() parameter). Is the result state true?

gsabhishek
19th February 2015, 10:58
If you have written something like your code snippet then the line edits are local in on_pushButton_clicked() and, most likely, shadowing the "right ones" line edits. You are entering values in the "right ones" line edits but the local ones are left empty. That's why you are getting nulls.
(1) see the output of the line edits as QStrings (remove toInt()). Are the strings empty? Do they contain what they should?
(2) see the result of the toInt() (do not default the first toInt() parameter). Is the result state true?

thx..but the strings are also null...I also had another function returning the values to the on_pushButton_clicked()..still same pob....how can I get the right line edits returning the values

Added after 36 minutes:

hey...I got it...thx...I accessed it thru...ui->lineEdit->text().toInt();

thx for the help