Results 1 to 7 of 7

Thread: Retrieving the data from the screen in the GUI

  1. #1
    Join Date
    Nov 2012
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Retrieving the data from the screen in the GUI

    What is the best widget to use to retrieve doubles or integers from the user on the screen?
    I am at a loss to figure out how to the get the data in order to manipulate it later in calculations.
    For example:
    int num1;
    int num2;

    int sum = num1 + num2

    if I was in a console application I would use cin to get the data from the user. How do I do that in the GUI environment through a form?

  2. #2
    Join Date
    Jun 2010
    Location
    Pretoria, South Africa
    Posts
    22
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Retrieving the data from the screen in the GUI

    QSpinBox and QDoubleSpinBox

  3. #3
    Join Date
    Nov 2012
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Retrieving the data from the screen in the GUI

    Thanks but what if I want to use a simple box like a textEdit box for the user to type the integer or float into?

  4. #4
    Join Date
    May 2009
    Location
    Canada
    Posts
    163
    Thanks
    7
    Thanked 20 Times in 20 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows Android

    Default Re: Retrieving the data from the screen in the GUI

    Quote Originally Posted by Newbe View Post
    Thanks but what if I want to use a simple box like a textEdit box for the user to type the integer or float into?
    Then do that. See QString::toInt() and QString::toFloat().

  5. #5
    Join Date
    Mar 2011
    Location
    Coimbatore,TamilNadu,India
    Posts
    382
    Thanks
    10
    Thanked 13 Times in 12 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Retrieving the data from the screen in the GUI

    Use TextEdit and retrieve the values in QString and then convert those values to whatever format you are in need..

  6. #6
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Retrieving the data from the screen in the GUI

    You can use QLineEdit, and set input mask to allow only integers / float. See the documentation of QLineEdit::setInputMask()
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  7. #7
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Retrieving the data from the screen in the GUI

    Quote Originally Posted by Newbe View Post
    Thanks but what if I want to use a simple box like a textEdit box for the user to type the integer or float into?
    QSpinBox and QDoubleSpinBox both allow direct user input additional to their "spin" input method.

    Cheers,
    _

Similar Threads

  1. Problem retrieving data from class
    By prophet0 in forum Newbie
    Replies: 9
    Last Post: 11th March 2012, 09:14
  2. [SOLVED] Retrieving data from QTableWidget
    By timmu in forum Qt Programming
    Replies: 0
    Last Post: 7th October 2011, 12:36
  3. Replies: 1
    Last Post: 16th September 2011, 09:15
  4. retrieving data from a QWT plot
    By mobucl in forum Qwt
    Replies: 1
    Last Post: 26th May 2011, 14:00

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.