【发布时间】:2016-04-04 19:36:57
【问题描述】:
我的环境是 Ubuntu 14.04 上的 CGAL 4.5 和 QT5。
我正在学习如何使用 CGAL 的 Qt interface 来渲染点、线、段等几何对象。网上似乎没有使用这个框架的例子,所以我现在很挣扎。
我似乎无法让我的测试代码工作。它编译但抛出一个段错误。
这是我在通过 QtCreator 创建的 QTwidgets 应用程序中的 MainWindow.cpp 文件中的代码。
#include <iostream>
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Qt/PointsGraphicsItem.h>
#include <CGAL/Qt/SegmentsGraphicsItem.h>
#include <vector>
typedef CGAL::Simple_cartesian<double> Kernel;
typedef Kernel::Point_2 Point_2;
typedef Kernel::Segment_2 Segment_2;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
scene = new QGraphicsScene(this);
ui->graphicsView->setScene(scene);
std::vector<Point_2> pts;
pts.push_back(Point_2(1,1));
pts.push_back(Point_2(10,10));
CGAL::Qt::PointsGraphicsItem< std::vector<Point_2> > graphical_points(&pts);
}
最后一行似乎是问题行。我的代码不断抛出段错误 在此刻。消息是
The inferior stopped because it received a signal from the operating system.
Signal name : SIGSEGV
Signal meaning : Segmentation fault
我在这个函数调用中做错了什么?我知道我必须将点添加到图形场景中,但这目前并不重要。
理想情况下,当代码运行时,它应该显示两个点,一个在 (1,1),另一个在 (10,10),一旦我将这些点添加到场景中。
Here 是 Pastebin 上完整的 PointsGraphicsItem.h 文件的链接。
【问题讨论】: