Results 1 to 4 of 4

Thread: add two integers

  1. #1
    Join Date
    Sep 2012
    Posts
    3
    Thanks
    1
    Qt products
    Qt3
    Platforms
    Windows

    Default add two integers

    how to add to integers,what is the easiest way to do it?

    ui->label2->setText(ui->plainTextEdit->toPlainText());
    int A,B,C;
    QString S1(ui->label->selectedText());
    QString S2(ui->label->selectedText());
    A = S1.toInt();
    B = S2.toInt();
    C = static_cast<int>(A)+ B; //need to add A + B but it gives 0 to me
    Last edited by Gishan; 8th September 2012 at 07:22.

  2. #2
    Join Date
    Feb 2011
    Location
    Bangalore
    Posts
    207
    Thanks
    20
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: add two integers

    Use QLabel::text(). Refer qt documentation available online or through qt4 assistant.

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

    Gishan (8th September 2012)

  4. #3
    Join Date
    Sep 2012
    Posts
    3
    Thanks
    1
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: add two integers

    please can u make this runnable
    i just need to add A and B
    Attached Files Attached Files

  5. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: add two integers

    Quote Originally Posted by Gishan View Post
    how to add to integers,what is the easiest way to do it?

    ui->label2->setText(ui->plainTextEdit->toPlainText());
    int A,B,C;
    QString S1(ui->label->selectedText());
    QString S2(ui->label->selectedText());
    A = S1.toInt();
    B = S2.toInt();
    C = static_cast<int>(A)+ B; //need to add A + B but it gives 0 to me
    The easiest way to add two integers is :
    Qt Code:
    1. int A,B,C;
    2. C = A+B;
    To copy to clipboard, switch view to plain text mode 

    You have a problem with getting text from widget or converting QString to int not with adding ints. Do you know what it is a debugger and how to use it (running program step by step) ?

Similar Threads

  1. Save 4 Integers in a QByteArray without memcpy
    By GonzoFist in forum Newbie
    Replies: 3
    Last Post: 17th May 2010, 23:15
  2. initialize QStringList with integers
    By tommy in forum Newbie
    Replies: 3
    Last Post: 13th May 2009, 06:48
  3. Only integers from QFontMetricsF width
    By StevenB in forum Qt Programming
    Replies: 3
    Last Post: 16th May 2008, 21:59
  4. how to get integers from mysql
    By eleanor in forum Qt Programming
    Replies: 9
    Last Post: 8th November 2007, 16:25
  5. Strings from LineEdit to Integers
    By Misko in forum Newbie
    Replies: 3
    Last Post: 12th August 2007, 11:11

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.