• 3097阅读
  • 6回复

[提问]我已经给跪了。。。看看这个类有什么问题啊。。。看看吧,感恩戴德了。。。 [复制链接]

上一主题 下一主题
离线zmx_zmx_zmx
 
只看楼主 倒序阅读 楼主  发表于: 2013-03-28
完全不知道哪里错了,提供给新的Qwidget的时候就段错误了。。。

#include <qwt_plot.h>
#include <qwt_plot_curve.h>
#include <qwt_legend.h>
#include <qwt_symbol.h>


class plot : public QwtPlot
{
    Q_OBJECT
public:
    plot(QWidget * parent = NULL);
    ~plot();
public slots:
    bool doOpen(const QString &,const int & ,const int &,const int &);//打开文件函数
    void dataShow();
    /*
    void find()                  
    void energy()            
    */
private:
    QString filename;           //文件名
    float divconst;          
   // float base;              


    int  number_of_trace;
    int trace_length;        
    int trace_long;            
    QPolygonF *container;
    QwtPlotCurve *temp_curve;  

    float fourbytechange(float num);

signals:
    void haveData();
};
离线zmx_zmx_zmx
只看该作者 1楼 发表于: 2013-03-28
#include "plot.h"
#include <QFile>
#include <fstream>
#include <QMessageBox>


plot::plot(QWidget *parent):QwtPlot(parent)
{
    //初始化类中的变量

    setTitle("sesmic wave ");
    filename="";
    divconst=20000;
    number_of_trace=0;
    trace_length=0;
    trace_long=0;

    //画布初始化
    setCanvasBackground(Qt::white);
    enableAxis(QwtPlot::xTop,true);
    enableAxis(QwtPlot::xBottom,false);
    setAxisScale(QwtPlot::yLeft,1250.0,0.0);          //暂时将坐标轴定义为1250*240的,后面需要再进行改变
    setAxisScale(QwtPlot::xTop,0.0,240);


    //connection
    connect(this,SIGNAL(haveData()),this,SLOT(dataShow()));
    resize(QSize(700,700));
}

bool plot::doOpen(const QString & filename_temp,const int &number_of_trace_temp,const int &tracelength_temp,const int &trace_long_temp)
{
//    if(sizeof(temp_curve)>sizeof(QwtPlotCurve))delete []temp_curve;
  //  if(sizeof(container)>sizeof(QPolygonF))delete []container;

    filename=filename_temp;
    number_of_trace=number_of_trace_temp;
    trace_length=tracelength_temp;
    trace_long=trace_long_temp;

    //if(!filename.endsWith(".sgy"))DIALOG_1

    std::ifstream fin;
    //DIALOG_2
    QByteArray temp_array =filename.toLocal8Bit();

    fin.open(temp_array.data(),std::ios::in);
    assert(fin);
//c++方式打开文件
//container 是指向QPloygonF的指针

    container = new QPolygonF[trace_length];

    for(int i=0;i<trace_length;i++)
    {

        for(int j=0;j<trace_long;j++)
        {
            float temp(0);
            fin.seekg(3840+(1250*4+240)*i+j*4);
            fin.read(reinterpret_cast<char *>(&temp),sizeof(temp));
            temp=fourbytechange(temp);

            *(container+i)<<QPointF(temp/divconst+i,j);
        }
     }
    fin.close();
    emit haveData();
    return 0;
}

void plot::dataShow()
{

    //DIALOG_filename
    setAxisScale(QwtPlot::yLeft,trace_long,0);
    setAxisScale(QwtPlot::xTop,0,trace_length);

    temp_curve  = new QwtPlotCurve[trace_length];
    for(int i=0;i<trace_length;i++)
    {

        (temp_curve+i)->setPen(QPen(Qt::blue,1));
        (temp_curve+i)->setRenderHint(QwtPlotItem::RenderAntialiased,true);
        (temp_curve+i)->setSamples(*(container+i));
        (temp_curve+i)->setXAxis(QwtPlot::xTop);
        (temp_curve+i)->setYAxis(QwtPlot::yLeft);
        (temp_curve+i)->attach(this);
        replot();
    }


}
plot::~plot()
{

    delete []temp_curve;
    delete []container;
}

float plot::fourbytechange(float num)
{
    union{float big;char small[4];}a,b;
    a.big=num;
    b.big=num;
    b.small[0]=a.small[3];
    b.small[1]=a.small[2];
    b.small[2]=a.small[1];
    b.small[3]=a.small[0];
    return b.big;
}
离线xsjqqq123

只看该作者 2楼 发表于: 2013-03-28
qwt,真心没研究过,但还是顶顶……

顺便问下
list=ui->textEdit->toPlainText().split(ui->lineEdit->text());//

ui->lineEdit->text() 里的是\n
但没用,如果用,之类的却行
离线zmx_zmx_zmx
只看该作者 3楼 发表于: 2013-03-28
回 2楼(xsjqqq123) 的帖子
哎,坑爹了,得到的错误是段错误,估计是指针哪里出错了,太坑爹了。。。
离线jdwx

只看该作者 4楼 发表于: 2013-03-28
回 3楼(zmx_zmx_zmx) 的帖子
在可能出错的地方前面加上断点,调试,单步运行。
发帖时要说明:操作系统、Qt版本、编译器,这样能更快的得到回复。
离线zmx_zmx_zmx
只看该作者 5楼 发表于: 2013-03-28
回 4楼(jdwx) 的帖子
已经不知道如何形容了 plot *a的时候就会出错,这是说明构造就有问题?
离线pxiao_xiao

只看该作者 6楼 发表于: 2013-03-28
plot *a的时候就会出错
你一点点的试试 把你构造函数先弄成空函数 看看到什么程度 多了哪条语句 给你报错了
快速回复
限100 字节
 
上一个 下一个