Results 1 to 3 of 3

Thread: Inputting values to GUI

  1. #1
    Join Date
    Feb 2015
    Posts
    2
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Inputting values to GUI

    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:n_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..

  2. #2
    Join Date
    Apr 2013
    Location
    Prague
    Posts
    258
    Thanks
    3
    Thanked 65 Times in 59 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Inputting values to GUI

    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?

  3. The following user says thank you to Radek for this useful post:

    gsabhishek (19th February 2015)

  4. #3
    Join Date
    Feb 2015
    Posts
    2
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Inputting values to GUI

    Quote Originally Posted by Radek View Post
    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
    Last edited by gsabhishek; 19th February 2015 at 10:58.

Similar Threads

  1. Replies: 5
    Last Post: 27th November 2014, 10:15
  2. Replies: 1
    Last Post: 31st December 2012, 08:06
  3. How to convert string hex values to its real binary values?
    By AttilaPethe in forum Qt Programming
    Replies: 1
    Last Post: 20th February 2012, 22:47
  4. Inputting Into Lists
    By kiyoutee in forum Newbie
    Replies: 2
    Last Post: 2nd March 2011, 07:48
  5. Replies: 2
    Last Post: 27th November 2008, 10:16

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.