【发布时间】:2013-09-05 08:49:04
【问题描述】:
我正在使用 GPS 接收器,它将使用这样的 C++ 程序在终端中连续打印 GPS 消息
Latitude:13.3 Longitude:80.25
Latitude:13.4 Longitude:80.27
Latitude:13.5 Longitude:80.28
我想在我的 c++ 程序(QT 应用程序)中获取这些数据
下面是我的完整程序代码
void QgsGpsPlotPluginGui::on_buttonBox_accepted()
{
QString myPluginsDir = "usr/lib/qgis/plugins";
QgsProviderRegistry::instance(myPluginsDir);
QgsVectorLayer * mypLayer = new QgsVectorLayer("/home/mit/Documents/Dwl/GIS DataBase/india_placename.shp","GPS","ogr");
QgsSingleSymbolRenderer *mypRenderer = new
QgsSingleSymbolRenderer(mypLayer->geometryType());
QList <QgsMapCanvasLayer> myLayerSet;
mypLayer->setRenderer(mypRenderer);
if (mypLayer->isValid())
{
qDebug("Layer is valid");
}
else
{
qDebug("Layer is NOT valid");
}
// Add the Vector Layer to the Layer Registry
QgsMapLayerRegistry::instance()->addMapLayer(mypLayer, TRUE);
// Add the Layer to the Layer Set
myLayerSet.append(QgsMapCanvasLayer(mypLayer, TRUE));
QgsMapCanvas * mypMapCanvas = new QgsMapCanvas(0, 0);
mypMapCanvas->setExtent(mypLayer->extent());
mypMapCanvas->enableAntiAliasing(true);
mypMapCanvas->setCanvasColor(QColor(255, 255, 255));
mypMapCanvas->freeze(false);
QgsFeature * mFeature = new QgsFeature();
QgsGeometry * geom = QgsGeometry::fromPoint(*p);
QGis::GeometryType geometryType=QGis::Point;
QgsRubberBand * mrub = new QgsRubberBand (mypMapCanvas,geometryType);
QgsPoint * p = new QgsPoint();
double latitude =13.3;
double longitude = 80.25;
p->setX(latitude);
p->setY(longitude);
mrub->setToGeometry(geom,mypLayer);
mrub->show()
}
在上面的代码中,我已经像这样手动输入了纬度和经度的值,
double latitude =13.3;
double longitude = 80.25;
p->setX(latitude);
p->setY(longitude);
但我需要从终端获取这些值。
这两个程序都是用 c++ 编写的,但它们属于不同的框架。
【问题讨论】:
-
需要更清楚地了解您想要做什么。您是否尝试从其他 c++ 程序中获取值?或者您是否尝试将“打印/输出”值读取到终端窗口? (这就是问题听起来的样子)。听起来其他 c++ 程序写入(比如说)标准输出,而您想要捕获该数据?都是用 Qt 编写的吗?
-
@code_fodder 谢谢。我想将终端中的其他程序打印输出带到 c++ 程序(QT 应用程序)
-
好的很酷...为您发布了一个选项,但我认为 sorin 是“最快”的路线,如果您想快速做到这一点,而不用担心花时间让它变得美好和未来证明:) ...一切都取决于你的最终目标是什么