Results 1 to 5 of 5

Thread: How to get data from inputs?

  1. #1
    Join Date
    May 2016
    Posts
    3
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Question How to get data from inputs?

    Hello,

    First of all, I want to warn you about my english - I'm not native.

    I want to create a really simple app for Windows. It may look like this:
    uQ41UYs.png

    First two inputs are QDoubleSpinBox types
    Third input is QLineEdit type.
    and finally, the Result is a QLabel

    All I want to do is simply add/multiply NUMBER_1 by NUMBER_3. The Result has to be changing dynamically.

    How to get data from those inputs? And then how to put this data into QLabel (Result)?

    Any ideas?

    Thanks.
    Last edited by fearlay; 17th May 2016 at 21:42.

  2. #2
    Join Date
    Nov 2015
    Posts
    41
    Thanks
    5
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to get data from inputs?

    Qt Code:
    1. QLineEdit::text()
    2. QLabel::setText()
    To copy to clipboard, switch view to plain text mode 

    and read Qt Documentation.

  3. #3
    Join Date
    May 2016
    Posts
    3
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to get data from inputs?

    Thank you so much for the help!

    Qt Code:
    1. double number_1 = ui->doubleSpinBox->value();
    2. double number_3 = ui->lineEdit->text().toDouble();
    3. double res = number_1*number_3;
    4. QString r = QString::number(res);
    5. ui->label_7->setText(r);
    To copy to clipboard, switch view to plain text mode 

    This works awesome! The only problem I have is that I want to display the result dynamically. I have already tried to do this by using Signals/Slots, but unfortunately I failed. Can someone give me a hint how to actually do this?

    Thanks.

  4. #4
    Join Date
    Nov 2015
    Posts
    41
    Thanks
    5
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to get data from inputs?

    Look for signals:

    Qt Code:
    1. QDoubleSpinBox::valueChanged(double d);
    2. QLineEdit::textChanged(const QString & text);
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jun 2011
    Posts
    5
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to get data from inputs?

    Hello,

    As Scope is mentioning you can use the signals connected to different slots.
    QDoubleSpinBox::valueChanged(double d);
    QLineEdit::textChanged(const QString & text);


    Here the tricky part for dynamically update is to have two bool variables, one for NUMBER_1 doublespinbox and the other for NUMBER_3 line edit. So in there respective slots you have to make them true and check for whether the other bool variable is true or not. If other variable is also true then proceed with the calculation and set the value to the Label. Important thing is we have to make both variables to false for next calculation.

    //Sample Code looks like.
    bool bIsNumber1 = false, bIsNumber3 = false;

    //slot connected to DoubleSpinBox signal
    void slotDoubleSpinNo1()
    {
    bIsNumber1 = true;
    if(bIsNumber3)
    {
    //do calculation and set the text to label.
    resultLable->setText();

    //reset the bool variables
    bIsNumber1 = false;
    bIsNumber3 = false;
    }
    }

    //Slot connected to LineEdit signal
    void slotLineEditNo3()
    {
    bIsNumber3 = true;
    if(bIsNumber1)
    {
    //do calculation and set the text to label.
    resultLable->setText();

    //reset the bool variables
    bIsNumber1 = false;
    bIsNumber3 = false;
    }
    }

    Hope it helps....

Similar Threads

  1. Replies: 1
    Last Post: 29th May 2014, 07:50
  2. unable to get uni-code inputs from another thread
    By Mohammad in forum Qt Programming
    Replies: 3
    Last Post: 15th November 2011, 14:56
  3. Need to find a way to save user inputs.
    By "BumbleBee" in forum Newbie
    Replies: 23
    Last Post: 4th November 2011, 14:10
  4. How to implement functionalities of other devices/inputs in Qt
    By qt_user in forum Qt for Embedded and Mobile
    Replies: 2
    Last Post: 9th October 2011, 10:32
  5. Replies: 0
    Last Post: 11th November 2008, 15:36

Tags for this Thread

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.