Results 1 to 8 of 8

Thread: Dynamic values for qSin and qCos giving error

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2016
    Posts
    4
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: Dynamic values for qSin and qCos giving error

    Hi,

    I tried all the way you have said.
    I'm getting correct value only if I gave values directly. (ie If I took value from a text field and assigned to an integer, then its giving wrong values for qCos and qSin).
    But if I print the value which I red from text filed using qDebug(), it'll get correct value.

    The same code I tried in PC. Its working fine.

    I'll add the program below which I hav done.

    main.cpp

    Qt Code:
    1. #include <QApplication>
    2. #include "dialog.h"
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication app(argc, argv);
    7. Dialog dialog;
    8. dialog.setMinimumHeight(725);
    9. dialog.setMinimumWidth(1000);
    10.  
    11. dialog.showMaximized();
    12. dialog.show();
    13.  
    14. return app.exec();
    15. }
    To copy to clipboard, switch view to plain text mode 

    dialog.cpp

    Qt Code:
    1. #include <QtDebug>
    2.  
    3. #include "dialog.h"
    4. Dialog::Dialog()
    5. {
    6. drawCircle =0;
    7. main_widget = new QWidget;
    8. menu_layout = new QVBoxLayout;
    9.  
    10. circleRadiusText =new QTextEdit("");
    11. circleRadiusText->setFixedHeight(30);
    12. circleRadiusText->setFixedWidth(130);
    13.  
    14. QPushButton *submitButton = new QPushButton("OK");
    15. submitButton->setFixedWidth(300);
    16.  
    17. menu_layout->addWidget(circleRadiusText);
    18. menu_layout->addWidget(submitButton);
    19. setLayout(menu_layout);
    20.  
    21. QObject::connect(submitButton, SIGNAL(clicked()),this, SLOT(draw_Circle()));
    22.  
    23. }
    24. void Dialog::draw_Circle()
    25. {
    26.  
    27. angle = circleRadiusText->toPlainText().toInt();
    28.  
    29. drawCircle =1;
    30. update();
    31. }
    To copy to clipboard, switch view to plain text mode 

    dialog.h

    Qt Code:
    1. #ifndef DIALOG_H
    2. #define DIALOG_H
    3.  
    4. #include <QDialog>
    5. #include <stdlib.h>
    6. #include <math.h>
    7. #include <cmath>
    8. #include <iostream>
    9. #include <stdio.h>
    10.  
    11. QT_BEGIN_NAMESPACE
    12. class QAction;
    13. class QGroupBox;
    14. class QLineEdit;
    15. class QMenuBar;
    16. class QTextEdit;
    17. #include <QMainWindow>
    18. #include <QTextEdit>
    19. #include <QString>
    20. #include <QtGui>
    21. #include <QPushButton>
    22. #include <QWidget>
    23. #include <QBoxLayout>
    24. #include <QPainter>
    25. #include <QPaintEvent>
    26. #include <QKeyEvent>
    27. #include <QGraphicsView>
    28. #include <qmath.h>
    29.  
    30. QT_END_NAMESPACE
    31.  
    32. class Dialog : public QDialog
    33. {
    34. Q_OBJECT
    35.  
    36. public:
    37. Dialog();
    38.  
    39. private slots:
    40. void draw_Circle();
    41. void keyPressEvent(QKeyEvent *event)
    42. {
    43. if(event->key() == Qt::Key_Q)
    44. {
    45. qApp->exit();
    46. }
    47. }
    48. void paintEvent(QPaintEvent *)
    49. {
    50. QPainter Painter(this);
    51. Painter.setRenderHint(QPainter::Antialiasing,true) ;
    52. if (drawCircle ==1)
    53. {
    54. int x1,y1,x2,y2;
    55. x1 =100;
    56. y1 = 100;
    57. x2 = 400;
    58. y2 = 400;
    59. int midx = 300;
    60. int midy = 300;
    61. int radius = 200;
    62. angle1 = 100;
    63.  
    64. qDebug()<< angle;
    65. qDebug()<< angle1;
    66. Painter.setBrush(QColor(Qt::white));
    67. Painter.drawEllipse(x1,y1,x2,y2);
    68. Painter.setPen(QPen(QColor(Qt::black)));
    69.  
    70. Painter.drawLine(midx, midy, midx+radius, midy);
    71. Painter.drawLine(midx, midy, midx+(radius*qCos(angle1*3.14/180)),midy+(radius*qSin(angle1*3.14/180))); // This will work fine in both PC and embedded board.
    72. Painter.drawLine(midx, midy, midx+(radius*qCos(angle*3.14/180)),midy+(radius*qSin(angle*3.14/180))); // Only working in PC
    73. }
    74. }
    75. public:
    76. QWidget *main_widget;
    77. QTextEdit *circleRadiusText;
    78. QVBoxLayout *menu_layout;
    79. int angle, angle1;
    80. int drawCircle;
    81.  
    82. };
    83.  
    84. #endif // DIALOG_H
    To copy to clipboard, switch view to plain text mode 

    By checking this program or by trying this program you can help me I guess.
    Waiting for your reply...
    Last edited by sreejithsjt; 18th May 2016 at 11:46. Reason: reformatted to look better

Similar Threads

  1. Replies: 1
    Last Post: 26th April 2016, 14:46
  2. Replies: 3
    Last Post: 30th April 2012, 07:39
  3. Replies: 4
    Last Post: 31st January 2012, 08:59
  4. WCHAR to QString giving error in vs2005
    By ucomesdag in forum Qt Programming
    Replies: 2
    Last Post: 1st May 2008, 23:25
  5. "make" is giving an error
    By Sarma in forum Qt Programming
    Replies: 6
    Last Post: 21st August 2006, 14:28

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