PDA

View Full Version : ActiveQt using free open source MapWindow activeX control



crey
23rd October 2006, 13:04
Hi,

I'm developing a basic GIS application using ActiveQt module and free open source activeX called MapWindow (http://www.mapwindow.org/). 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 (http://www.mapwindow.org/wiki/index.php/MapWinGIS_Developer%27s_Guide).
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 (http://www.mapwindow.org/samplecode.php) on the web and it works perfectly.

Thanks for your time,

Carlos.

sungaoyong
2nd November 2006, 05:10
Open Function exits in class ITable,not IShapefile ,see mapwindow.h

Romano006
7th March 2010, 17:04
Hello,

I exactly have the same problem about using a shapefile. Actually, I don't manage to call the CreateNew() or Open() methods of my Shapefile object without getting a crash of my application during runtime.
I am using Visual C++ 2008 but I have the same problems with QtCreator.
Please let me know if you know anything about how to load a Shape file stored on disk and how to associate it with a Map object.

Thanks in advance,
Romain.

Teva
7th October 2015, 20:43
I'm trying to use MapWinGIS.ocx in my QT application. I got the header and lib files of MapWindow. Is there anyway I could get the source code for simply loading shape files?
Thanks.



Hi,

I'm developing a basic GIS application using ActiveQt module and free open source activeX called MapWindow (http://www.mapwindow.org/). 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 (http://www.mapwindow.org/wiki/index.php/MapWinGIS_Developer%27s_Guide).
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 (http://www.mapwindow.org/samplecode.php) on the web and it works perfectly.

Thanks for your time,

Carlos.