Hi,
I'm developing a basic GIS application using ActiveQt module and free open source activeX called
MapWindow. I'm using Visual Studio .NET 2003 and Qt 4.2.
This activeX control supports basic GIS drawing and shapefile manipulation. The ActiveX control's API is
here.
I've used
dumpcpp tool to generate the Qt's wrapper to this control. I enclose this two generated files called
mapwindow.h and
mapwindow.cpp in the zip file.
I've created a simple widget with the designer and created "manually" the
QAxWidget. This is the code:
#ifndef MPWTEST_H
#define MPWTEST_H
#include <QtGui/QMainWindow>
#include <QAxObject>
#include <QDebug>
#include <QFile>
#include <QUuid>
#include <QTextStream>
#include "mapwindow.h"
#include "ui_mpwtest.h"
using namespace MapWinGIS;
class MPWTEST : public QMainWindow
{
Q_OBJECT
public:
MPWTEST(QWidget *parent = 0, Qt::WFlags flags = 0);
~MPWTEST();
private:
Ui::MPWTESTClass ui;
Map mapObject2;
};
#endif // MPWTEST_H
*************************
***** End of file ***********
*************************
#include "mpwtest.h"
#include <qaxobject.h>
#include <qaxwidget.h>
MPWTEST::MPWTEST(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
{
ui.setupUi(this);
//mapObject = new Map(this);
if (!mapObject2.isNull())
{
ui.vboxLayout->addWidget(&mapObject2);
mapObject2.NewDrawing(dlScreenReferencedList);
mapObject2.DrawCircle(3,4,12,QColor("red"),true);
}
}
*************************
***** End of file ***********
*************************
This example works ok, as you see, it draws a red circle on the 3,4 coordiantes.
The problem comes when i try to load a
Shapefile using
Shapefile Object from the ActiveX.
I'm trying to create a
Shapefile object and call "Open" function. As stated in the MapWindow doc, the signature for Open in VisualBasic is:
Function Open(ShapefileName As String, Optional cBack As MapWinGIS.ICallback) As Boolean.
So, in the Qt's wrapper
mapwindow.h it shows:
inline bool Open(const QString& ShapefileName, MapWinGIS::ICallback* cBack);
Being
ICallback a parameter not supported in ActiveQt, I cannot use dynamicCall in order to use "Open" function. So I try to use the wrapper:
1 Shapefile *shp = new Shapefile;
2 if (shp)
3 {
4 bool result = shp->Open("country.shp",NULL);
5 if (result)
6 {
7 mapObject2.AddLayer((IDispatch *)shp,true);
8 }
9 }
This code doesn't work!. It stops in line 4 showing
"ASSERT: "id < 0" in file .\qaxbase.cpp, line 3598
It seems the object is not being properly initalized. If i use, IShapefile instead of Shapefile changing line 1
1 IShapefile *shp = new IShapefile;
it shows a runtime Qt warning after executing line 4:
QAxBase::qt_metacall: Object is not initialized, or initialization failed
and the boolean variable
result is always false.
Having
{c0eac9eb-1d02-4bd9-8dab-4bf922c8cd13} as the Uid for the
Shapefile control, I try the "
queryInterface" way with:
1 IShapefile *shp = 0;
2 mapObject2.queryInterface(QUuid("{c0eac9eb-1d02-4bd9-8dab-4bf922c8cd13}"),(void**)&shp);
3 if (shp)
4 {
5 bool result = shp->Open("country.shp",NULL);
6 if (result)
7 {
8 mapObject2.AddLayer((IDispatch *)shp,true);
9 }
10 }
11 else
12 {
13 qDebug() << "Object creation failed.";
14 }
Executing this code, shp remains 0 after line 3...mmmm, I don't know if I am misunderstanding something or the Uid for the Shapefile is incorrect or....
Do you know what's happening? I've compiled and run the example C++ Simple Map Project (Visual Studio 2003) from the
sample code on the web and it works perfectly.
Thanks for your time,
Carlos.
Bookmarks