Results 1 to 5 of 5

Thread: Qt Calculator

  1. #1
    Join Date
    Jul 2012
    Posts
    11
    Thanks
    6

    Default Re: Qt Calculator


    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3.  
    4. MainWindow::MainWindow(QWidget *parent) :
    5. QMainWindow(parent),
    6. ui(new Ui::MainWindow)
    7. {
    8. ui->setupUi(this);
    9. }
    10.  
    11. MainWindow::~MainWindow()
    12. {
    13. delete ui;
    14. }
    15.  
    16. void MainWindow::on_actionClose_triggered() //Close the Program "An action in the file menu"
    17. {
    18.  
    19. }
    20.  
    21. void MainWindow::on_pushButton_clicked() //Addition
    22. {
    23.  
    24. }
    25.  
    26. void MainWindow::on_pushButton_2_clicked() //Subtraction
    27. {
    28.  
    29. }
    30.  
    31. void MainWindow::on_pushButton_3_clicked() //Divishion
    32. {
    33.  
    34. }
    35.  
    36. void MainWindow::on_pushButton_4_clicked() //Multiplication
    37. {
    38.  
    39. }
    To copy to clipboard, switch view to plain text mode 
    As you can see above im trying to creat a Calculator but iv run into a small problem im extreemly good with C++ which is what im codeing with but i dont now how to use buttons to execute a function or how to hold what is typed in a textline in a variable so if some one could tell me how to do that or show me where i can find a tutorial for it i would be greatfull

    also if anyone nows how to close the main window through an action i created called exit that would be great
    Thanks in advance sorry if this is noobie
    Last edited by Johnnyj2j; 7th July 2012 at 16:36.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt Calculator

    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    Johnnyj2j (9th July 2012)

  4. #3
    Join Date
    Jul 2012
    Posts
    11
    Thanks
    6

    Default Re: Qt Calculator

    thanks for the example but i find it hard to follow everything would you mind just stating how to

    1) Call on text in textline
    2) Activate Function if button pressed
    3) extit through action

    if its not asking to much...

  5. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Qt Calculator

    ... im extreemly good with C++ ... how to hold what is typed in a textline in a variable
    Really? It's just C++ and the necessary functions are well documented. Qt does not make C++ suddenly change its rules.
    Qt Code:
    1. QString value = ui->lineedit->text();
    To copy to clipboard, switch view to plain text mode 

    1) QLineEdit::text()
    2) Connect the QPushButton::clicked() signal to a function that is declared as a slot, or rely on the Qt Designer automatic connection by name as you are doing. These sorts of connections are shown in almost every single Qt example in the manual (widget examples more than QML examples).

    3) Close the last remaining top level application window with QWidget::close() as in almost every single Qt example in the manual, or call QCoreApplication::quit() directly or through the qApp object.

    The manual is your friend.

  6. The following user says thank you to ChrisW67 for this useful post:

    Johnnyj2j (9th July 2012)

  7. #5
    Join Date
    Aug 2011
    Location
    California, USA
    Posts
    24
    Thanks
    4
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt Calculator

    2) Activate Function if button pressed
    As an alternative to ChrisW67's answer, whatever you put in the scope of the following function will be called whenever the "pushButton" widget is "clicked" in MainWindow's form.

    Qt Code:
    1. void MainWindow::on_pushButton_clicked()
    2. {
    3. //Code to execute when pushButton is clicked
    4. }
    To copy to clipboard, switch view to plain text mode 

    Hope this helps!

    Chris

  8. The following user says thank you to chriskon149 for this useful post:

    Johnnyj2j (9th July 2012)

Similar Threads

  1. a simple calculator in C++
    By thehindutimes in forum General Programming
    Replies: 4
    Last Post: 4th May 2011, 20:31
  2. A little calculator problem
    By bijan311 in forum Newbie
    Replies: 37
    Last Post: 15th March 2010, 01:46
  3. Calculator Builder Example
    By janus in forum Newbie
    Replies: 1
    Last Post: 19th April 2008, 09:23
  4. From calculator: how to draw
    By mattia in forum Newbie
    Replies: 1
    Last Post: 26th October 2007, 11:22
  5. Need help with a basic calculator
    By Morea in forum Qt Programming
    Replies: 7
    Last Post: 25th March 2006, 19:18

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
  •  
Qt is a trademark of The Qt Company.