Results 1 to 3 of 3

Thread: HOW to do this Qt ?

  1. #1
    Join Date
    Jan 2010
    Posts
    63
    Qt products
    Qt4
    Platforms
    Windows

    Default HOW to do this Qt ?

    Here is a code snipet of calculating the average and displaying it on the console
    Qt Code:
    1. include <iostream>
    2. include <iomanip>
    3. using std::cout;
    4. using std::cin;
    5. using std::setw();
    6. int main()
    7. {
    8. int number,sum=0;
    9. float mean=0;
    10. for (int i=1;i<5;++i)
    11. {
    12. cout<<"\nenter number->";
    13. cin>> number;
    14. sum=+number;
    15. }
    16. mean= sum/5;
    17. cout <<"mean="<<setw(2)<<mean;
    18. }
    To copy to clipboard, switch view to plain text mode 
    Running in console mode

    Enter number->23
    Enter number->5
    Enter numer-> 6
    Enter number->123
    Enter number->4
    mean=32.2

    How could this be done in a GUI with tthe same results ?
    Is it possible ?
    Last edited by Petr_Kropotkin; 31st January 2010 at 18:32.

  2. #2
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: HOW to do this Qt ?

    You already have a piece of code accepting input (the one with the line edit). Implementing the behaviour you want is something you should try yourself first.
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  3. #3
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: HOW to do this Qt ?

    Use QtDesigner to put 5 lineEdit's onto a form, along with a submit button and a label. Make the submit button calculate the average and put it in the label.

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.