qSin和qCos的动态值给出错误

时间:2016-05-25 09:08:45

标签: c++ qt embedded-linux

我正在使用embedded-qt-4.8.5开发一个QT应用程序,用于绘制一个内部有两条线的圆,从原点开始,如图所示。 第一行将从原点到右侧朝向圆圈。第二行将是角度"角度"从逆时针方向的第一行开始。见图以便澄清。

Figure

我使用的代码是

main.cpp

#include <QApplication>
#include "dialog.h"

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    Dialog dialog;
    dialog.setMinimumHeight(725);
    dialog.setMinimumWidth(1000);

    dialog.showMaximized();
    dialog.show();

    return app.exec();
}

dialog.cpp

#include <QtDebug>

#include "dialog.h"
Dialog::Dialog()
{
    drawCircle =0;
    main_widget = new QWidget;
    menu_layout = new QVBoxLayout;

    circleRadiusText =new QTextEdit("");
    circleRadiusText->setFixedHeight(30);
    circleRadiusText->setFixedWidth(130);

    QPushButton *submitButton = new QPushButton("OK");
    submitButton->setFixedWidth(300);

    menu_layout->addWidget(circleRadiusText);
    menu_layout->addWidget(submitButton);
    setLayout(menu_layout);

    QObject::connect(submitButton, SIGNAL(clicked()),this, SLOT(draw_Circle()));

}
void Dialog::draw_Circle()
{

    angle =  circleRadiusText->toPlainText().toInt();

    drawCircle =1;
    update();
}

dialog.h

#ifndef DIALOG_H
#define DIALOG_H

#include <QDialog>
#include <stdlib.h>
#include <math.h>
#include <cmath>
#include <iostream>
#include <stdio.h>

QT_BEGIN_NAMESPACE
class QAction;
class QDialogButtonBox;
class QGroupBox;
class QLineEdit;
class QMenuBar;
class QPushButton;
class QTextEdit;
#include <QMainWindow>
#include <QTextEdit>
#include <QString>
#include <QtGui>
#include <QPushButton>
#include <QWidget>
#include <QBoxLayout>
#include <QPainter>
#include <QPaintEvent>
#include <QKeyEvent>
#include <QGraphicsView>
#include <qmath.h>

QT_END_NAMESPACE

class Dialog : public QDialog
{
    Q_OBJECT

public:
    Dialog();

private slots:
    void draw_Circle();
    void keyPressEvent(QKeyEvent *event)
    {
        if(event->key() == Qt::Key_Q)
        {
            qApp->exit();
        }
    }
    void paintEvent(QPaintEvent *)
    {
        QPainter Painter(this);
        Painter.setRenderHint(QPainter::Antialiasing,true) ;
        if (drawCircle ==1)
            {
                int x1,y1,x2,y2;
                x1 =100;
                y1 = 100;
                x2 = 400;
                y2 = 400;
                int midx = 300;
                int midy = 300;
                int radius = 200;

                qDebug()<< angle;
                Painter.setBrush(QColor(Qt::white));
                Painter.drawEllipse(x1,y1,x2,y2);
                Painter.setPen(QPen(QColor(Qt::black)));

                Painter.drawLine(midx, midy, midx+radius, midy);
                Painter.drawLine(midx, midy, midx+(radius*qCos(angle*3.14/180)),midy+(radius*qSin(angle*3.14/180))); // Only working in PC
            }
     }
public:
        QWidget *main_widget;
        QTextEdit *circleRadiusText;
        QVBoxLayout *menu_layout;
        int angle;
        int drawCircle;

};

#endif // DIALOG_H

但是在绘制第二行时我遇到了运行时错误...... 我已经评论了绘制第二行并检查的说明。第一行正确绘制。角度值是从QTextEdit读取的,从QTextEdit转换为整数后的角度值也是正确的。 相同的代码在PC中的QT Creator上运行良好。

  

对齐陷阱:未在[&lt; 764c58cc&gt;]处理指令ed840a00

     

未处理的错误:0x3fc8f5c3

处的对齐异常(0x801)

如果我将角度值设为静态,它将绘制线条而没有任何错误。也就是说,

int angle1 = 100;
Painter.drawLine(midx, midy, midx+(radius*qCos(angle1*3.14/180)), midy+(radius*qSin(angle1*3.14/180)));

请帮我解决这个问题。 提前谢谢。

0 个答案:

没有答案