Results 1 to 2 of 2

Thread: Weird Symbols when using toInt()

  1. #1
    Join Date
    May 2013
    Posts
    47
    Qt products
    Qt5
    Platforms
    Windows

    Default Weird Symbols when using toInt()

    Hello Guys,
    I been facing a problem lately with toInt() conversion, I get wierd symbols in the label i link the toInt() to . I get "@!" and sometimes the whole string of event handler comes out for eg "void Calculator:n_Num7_clicked()"
    The following are my codings
    .h
    Qt Code:
    1. #ifndef CALCULATOR_H
    2. #define CALCULATOR_H
    3.  
    4. #include <QWidget>
    5.  
    6. #include <QDebug>
    7. #include <QtCore>
    8. #include<QtGui>
    9.  
    10. namespace Ui {
    11. class Calculator;
    12. }
    13.  
    14. class Calculator : public QWidget
    15. {
    16. Q_OBJECT
    17.  
    18. public:
    19. explicit Calculator(QWidget *parent = 0);
    20. ~Calculator();
    21.  
    22. private slots:
    23. void on_Num1_clicked();
    24.  
    25. void on_Num2_clicked();
    26.  
    27.  
    28. void on_Add_clicked();
    29.  
    30.  
    31.  
    32. private:
    33. Ui::Calculator *ui;
    34. };
    35.  
    36. #endif // CALCULATOR_H
    To copy to clipboard, switch view to plain text mode 
    .cpp
    Qt Code:
    1. #include "calculator.h"
    2. #include "ui_calculator.h"
    3. int num1=0;
    4. QString str;
    5.  
    6.  
    7.  
    8. Calculator::Calculator(QWidget *parent) :
    9. QWidget(parent),
    10. ui(new Ui::Calculator)
    11. {
    12. ui->setupUi(this);
    13. ui->lineEdit->setText("");
    14.  
    15. }
    16.  
    17. Calculator::~Calculator()
    18. {
    19. delete ui;
    20. }
    21.  
    22. void Calculator::on_Num2_clicked()
    23. {
    24. ui->lineEdit->setText(ui->lineEdit->text()+"2");
    25. }
    26.  
    27.  
    28. void Calculator::on_Add_clicked()
    29. {
    30.  
    31. str=ui->lineEdit->text();
    32. num1=str.toInt();
    33. ui->label->setText(""+num1);
    34. qDebug()<<num1;
    35.  
    36. }
    To copy to clipboard, switch view to plain text mode 

    The qDebug() works perfectly fine , it is able to show the numbers
    Thank you in advance

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android
    Thanked 342 Times in 324 Posts

    Default Re: Weird Symbols when using toInt()

    You add integer to string constant in line 33. I don't think this is what you wanted.
    Use QString class methods to convert numbers to strings (QString::number, ::arg, ::setNum)

Similar Threads

  1. qt with debugging symbols
    By valerianst in forum Qt Programming
    Replies: 17
    Last Post: 23rd September 2013, 10:37
  2. weird weird mingw32-make
    By KillGabio in forum Qt Programming
    Replies: 19
    Last Post: 20th January 2012, 21:09
  3. /usr/bin/ld: Undefined symbols:
    By ataffard in forum Qt Programming
    Replies: 0
    Last Post: 2nd May 2008, 02:24
  4. math symbols
    By genick bar-meir in forum Qt Programming
    Replies: 3
    Last Post: 17th August 2007, 08:29
  5. greek symbols
    By genick bar-meir in forum Qt Programming
    Replies: 2
    Last Post: 17th July 2007, 23:44

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.