Hi, I know this is an old thread, but I just got this working myself. I found this thread while doing some searching on my own and it was no help.
So, I thought I would reply and show what I did to make MapLink Pro 6.0 work with Qt 4.8.
Firstly, make a custom QWidget class. Then in the widget's constructor, set the following attributes.
setAttribute(Qt::WA_NoBackground, true);
setAttribute(Qt::WA_NoSystemBackground, true);
setAttribute(Qt::WA_PaintOnScreen, true);
setAutoFillBackground(false);
setAttribute(Qt::WA_OpaquePaintEvent, true);
setAttribute(Qt::WA_NoBackground, true);
setAttribute(Qt::WA_NoSystemBackground, true);
setAttribute(Qt::WA_PaintOnScreen, true);
setAutoFillBackground(false);
setAttribute(Qt::WA_OpaquePaintEvent, true);
To copy to clipboard, switch view to plain text mode
You will also need to override the paintEngine function like so:
QPaintEngine* paintEngine
() const //Works in conjunction with WA_PaintOnScreen {
return NULL;
}
QPaintEngine* paintEngine() const //Works in conjunction with WA_PaintOnScreen
{
return NULL;
}
To copy to clipboard, switch view to plain text mode
Override the paintEvent:
{
if (m_bInitialUpdate) //Set to true in constructor
{
MainWindow* main = static_cast<MainWindow*>(parentWidget()->parentWidget());
if (main)
{
HWND hWnd = (HWND)winId();
m_drawingSurface = new TSLNTSurface(hWnd, false);
m_drawingSurface->setOption( TSLOptionDoubleBuffered, true ) ;
m_drawingSurface->wndResize( 0, 0, rect().width(), rect().height() ) ;
m_drawingSurface->addDataLayer(main->m_dataLayer, "map");
m_drawingSurface->addDataLayer(main->m_stdDataLayer, "overlay"); //Not needed if you don't want an overlay
m_drawingSurface->reset(false);
m_bMapLoaded = true;
m_drawingSurface->setDataLayerProps( "map" , TSLPropertyBuffered , 1 ) ;
}
m_bInitialUpdate = false;
}
if (m_drawingSurface)
m_drawingSurface->drawDU(rect().left(), rect().top(), rect().right(), rect().bottom(), true, true);
}
void QMapView::paintEvent(QPaintEvent *)
{
if (m_bInitialUpdate) //Set to true in constructor
{
MainWindow* main = static_cast<MainWindow*>(parentWidget()->parentWidget());
if (main)
{
HWND hWnd = (HWND)winId();
m_drawingSurface = new TSLNTSurface(hWnd, false);
m_drawingSurface->setOption( TSLOptionDoubleBuffered, true ) ;
m_drawingSurface->wndResize( 0, 0, rect().width(), rect().height() ) ;
m_drawingSurface->addDataLayer(main->m_dataLayer, "map");
m_drawingSurface->addDataLayer(main->m_stdDataLayer, "overlay"); //Not needed if you don't want an overlay
m_drawingSurface->reset(false);
m_bMapLoaded = true;
m_drawingSurface->setDataLayerProps( "map" , TSLPropertyBuffered , 1 ) ;
}
m_bInitialUpdate = false;
}
if (m_drawingSurface)
m_drawingSurface->drawDU(rect().left(), rect().top(), rect().right(), rect().bottom(), true, true);
}
To copy to clipboard, switch view to plain text mode
In our main window:
TSLErrorStack::clear();
TSLDrawingSurface::loadStandardConfig();
QString err
(TSLErrorStack
::errorString());
if (!err.isNull())
qDebug(qPrintable(err));
m_dataLayer = new TSLMapDataLayer();
m_dataLayer->loadData(filename.toStdString().c_str());
err = TSLErrorStack::errorString("Cannot load map\n");
if (!err.isNull())
{
m_bMapLoaded = false;
qDebug(qPrintable(err));
}
m_stdDataLayer = new TSLStandardDataLayer();
TSLErrorStack::clear();
TSLDrawingSurface::loadStandardConfig();
QString err(TSLErrorStack::errorString());
if (!err.isNull())
qDebug(qPrintable(err));
m_dataLayer = new TSLMapDataLayer();
QString filename = QFileDialog::getOpenFileName(this, "Open map"); //Get a map to open
m_dataLayer->loadData(filename.toStdString().c_str());
err = TSLErrorStack::errorString("Cannot load map\n");
if (!err.isNull())
{
m_bMapLoaded = false;
qDebug(qPrintable(err));
}
m_stdDataLayer = new TSLStandardDataLayer();
To copy to clipboard, switch view to plain text mode
In the .pro file:
LIBS += -L<MapLinkDirHere>/lib -lMapLink
INCLUDEPATH += <MapLinkDirHere>/include
DEPENDPATH += <MapLinkDirHere>/include
LIBS += -L<MapLinkDirHere>/lib -lMapLink
INCLUDEPATH += <MapLinkDirHere>/include
DEPENDPATH += <MapLinkDirHere>/include
To copy to clipboard, switch view to plain text mode
When I used -lMapLinkd, there we crashes. Using the non-debug library works fine and there still seems to be debug information available.
This should be all you need to get MapLink to draw a map in your custom QWidget. Override methods for mouse events, resize events, keyboard events as you need.
Make sure to include "MapLink.h" where needed!
Bookmarks