我是靠谱客的博主 单薄手链,这篇文章主要介绍QCustomPlot使用过程中出现的错误,现在分享给大家,希望可以做个参考。

我们知道在使用一个类的指针时,应先在头文件中声明,在构造函数中初始化或者new出来,一定不能不初始化,否则会出现内存错误。在析构函数中还应该把该指针delete掉,并且让其为NULL。

复制代码
1
2
3
4
5
if(p != NULL) { delete p; p = NULL; }

然而我的项目在想用QCumstomPlot画圆时,使用了QCumstomPlot的QCPCurve类。主要代码如下:

声明:

复制代码
1
QCPCurve *rotaryErrCurve;

创建:

复制代码
1
rotaryErrCurve = new QCPCurve(ui->rotaryErrWidget->xAxis, ui->rotaryErrWidget->yAxis);

其他设置以及使用就不多赘述。在析构函数中:

复制代码
1
2
3
4
if(rotaryErrCurve != NULL){ delete rotaryErrCurve; rotaryErrCurve = NULL; }

将这些部分添加到我原有工程里之后,老是出现错误:

C:Program Files (x86)SogouInputComponentsError - RtlWerpReportException failed with status code :-1073741823. Will try to launch the process directly

程序异常结束。

G:luoyong51daqbuild-51daq-Desktop_Qt_5_6_3_MinGW_32bit-Releaserelease51daq.exe crashed.

我们知道这就是访问不存在或者不正确的地址造成的。在已知其他部分功能正常的情况下,复返检查新加部分也没有发现错误。直至在打开QCusomPlot的HELP文件,看到QCPCurve的构造函数的说明部分如下:

复制代码
1
2
QCPCurve::QCPCurve (QCPAxis * keyAxis,explicit QCPAxis * valueAxis ) Constructs a curve which uses keyAxis as its key axis ("x") and valueAxis as its value axis ("y").
复制代码
1
keyAxis and valueAxis must reside in the same QCustomPlot instance and not have the same orientation.
复制代码
1
2
If either of these restrictions is violated, a corresponding message is printed to the debug output (qDebug), the construction is not aborted, though. The created QCPCurve is automatically registered with the QCustomPlot instance inferred from keyAxis.
复制代码
1
This QCustomPlot instance takes ownership of the QCPCurve, so do not delete it manually but use QCustomPlot::removePlottable() instead.

前面部分都挺正常的,看到最后一句话我坐不住了。。。

复制代码
1
do not delete it manually but use QCustomPlot::removePlottable() instead.

然后我把delete部分改为:

复制代码
1
2
3
4
5
6
if(rotaryErrCurve != NULL) { ui->rotaryErrWidget->removePlottable(0); rotaryErrCurve = NULL; }

就好了。。。。

教训:

在使用一个不熟悉的类时要仔细阅读它的说明文档,不要想当然。

最后

以上就是单薄手链最近收集整理的关于QCustomPlot使用过程中出现的错误的全部内容,更多相关QCustomPlot使用过程中出现内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(116)

评论列表共有 0 条评论

立即
投稿
返回
顶部