在完全按照iobject c++教程,编写Getting Started示例时,进行到教程《打开工作空间中的地图并显示》时,编译正常,但运行时,会报错中断。软件环境是win10 x64, vs2015,qt5.9.8,编译配置是Debug x86。上述问题,均可正常编译,运行时异常。
#include "gettingstarted.h"
#include <QFileDialog>
#include <QMessageBox>
#include "qmapcontrol.h"
#include "translator.h"
#include "Workspace/UGWorkspace.h"
#include "Map/UGMap.h"
GettingStarted::GettingStarted(QWidget *parent)
: QMainWindow(parent)
{
setupUI(this);
addConnect();
}
void GettingStarted::setupUI(QMainWindow* pMainWindows)
{
pMainWindows->setWindowTitle("SuperMap iObeject C++ GettingStarted");
pMainWindows->resize(800, 600);
qMapControl = new QMapControl;
pMainWindows->setCentralWidget(qMapControl);
mainToolBar = new QToolBar(pMainWindows);
pMainWindows->addToolBar(Qt::TopToolBarArea, mainToolBar);
addMapAction(pMainWindows);
qMapControl->setFocus();
}
void GettingStarted::addMapAction(QMainWindow* pMainWindows)
{
actionOpen = new QAction(QIcon(":/Resources/Image_Open.png"), "Open", this);
mainToolBar->addAction(actionOpen);
actionViewEntire = new QAction(QIcon(":/Resources/Entire.png"), "View Entire", this);
mainToolBar->addAction(actionViewEntire);
actionZoomin = new QAction(QIcon(":/Resources/Zoomin.png"), "Zoom In", this);
mainToolBar->addAction(actionZoomin);
actionZoomout = new QAction(QIcon(":/Resources/Zoomout.png"), "Zoom Out", this);
mainToolBar->addAction(actionZoomout);
actionPan = new QAction(QIcon(":/Resources/Pan.png"), "Pan", this);
mainToolBar->addAction(actionPan);
actionCalcLength = new QAction(QIcon(":/Resources/Length.png"), "Length", this);
mainToolBar->addAction(actionCalcLength);
actionCalcArea = new QAction(QIcon(":/Resources/Area.png"), "Area", this);
mainToolBar->addAction(actionCalcArea);
actionCalcAngle = new QAction(QIcon(":/Resources/Angle.png"), "Angle", this);
mainToolBar->addAction(actionCalcAngle);
}
void GettingStarted::addConnect()
{
connect(actionOpen, &QAction::triggered, this, &GettingStarted::openMap);
connect(actionViewEntire, &QAction::triggered, this, &GettingStarted::viewEntire);
connect(actionZoomin, &QAction::triggered, this, &GettingStarted::zoomIn);
connect(actionZoomout, &QAction::triggered, this, &GettingStarted::zommOut);
connect(actionPan, &QAction::triggered, this, &GettingStarted::pan);
}
void GettingStarted::openMap()
{
UGWorkspace* pWorkspace = new UGWorkspace();
UGMap* pMap = qMapControl->GetMap();
pMap->SetLineSmoothingMode(false);
if (pWorkspace == NULL || pMap == NULL)
{
QMessageBox::critical(this, "ERROR", QString::fromUtf8("初始化失败"));
return;
}
QString qStrPath = QFileDialog::getOpenFileName(this
, QString::fromUtf8("OpenWorkSpace")
, "F:\other\supermap-iobjectscpp\sample\data"
, tr("smwu(*.smwu)"));
if (pWorkspace->Open(Translator::QStr2UGStr(qStrPath)))
{
pMap->SetWorkspace(pWorkspace);
}
else
{
QMessageBox::critical(this, "ERROR", QString::fromUtf8("工作空间打开失败"));
return;
}
UGString mapName = pWorkspace->m_MapStorages.GetNameAt(0);
if (!pMap->Open(mapName))
{
QMessageBox::critical(this, "ERROR", QString::fromUtf8("打开地图失败"));
return;
}
qMapControl->Refresh();
}
void GettingStarted::zoomIn()
{
qMapControl->ZoomIn();
}
void GettingStarted::zommOut()
{
qMapControl->ZoomOut();
}
void GettingStarted::viewEntire()
{
qMapControl->ViewEntire();
}
void GettingStarted::pan()
{
qMapControl->Pan();
}