[Interest] Passing QML mapobjects (MapCircle) to QML maps through C++

Kishore J kitts.mailinglists at gmail.com
Wed Aug 24 19:06:41 CEST 2016


Thanks Jason. I have been inching forward here and have made some progress.
I've hit another issue that I'll raise as another topic.

On Wed, Aug 17, 2016 at 9:55 PM Jason H <jhihn at gmx.com> wrote:

> "Do not try and bend the spoon, that's impossible. Instead, only try to
> *realize* the truth...*there is no spoon*. Then you will see it is not
> the spoon that bends, it is only your self that bends" - Spook Kid, The
> Matrix
>
> QML is not a language. It is ECMA Script (javascript) implemented by a an
> engine called "V4".  The C++ Meta Object Compiler coupled with the V4
> engine make the easy interop possible.
>
> If your MapItem is a QObject-derived class, then the MOC takes care of all
> the heavy lifting. Your Q_PROPERTYs are exposed as poperties, your slots
> are exposed, your signals are exposed.  If you want to create a an instance
> of a C++ item in QML, then read
> http://doc.qt.io/qt-5/qtqml-javascript-dynamicobjectcreation.html
>
> Alternatively, if your mapitem is jsut data, you could if you wanted,
> create a simple javascript Object which will be converted automatically to
> a QVariant and handle that accordingly. But it sounds like the C++ approach
> is best.
>
>
>
> *Sent:* Tuesday, August 16, 2016 at 2:44 PM
>
> *From:* "Kishore J" <kitts.mailinglists at gmail.com>
> *To:* interest at qt-project.org
> *Subject:* Re: [Interest] Passing QML mapobjects (MapCircle) to QML maps
> through C++
>
>
>
> On 15-Aug-2016 8:47 PM, "Jason H" <jhihn at gmx.com> wrote:
> >
> > I assume you men a geogrpahical map, as QMap is something else entirely.
>
> Yes. I was talking of geographical map.
>
> > It is trivial to interop between C++ and QML. Depending on how you do
> it, you can just set a context property  as a QObject-derived class in the
> C++ API. Otherwise you have to use it as a MetaType.
> >
> > http://doc.qt.io/qt-5/qtqml-cppintegration-data.html
> > http://doc.qt.io/qt-5/qtqml-cppintegration-definetypes.html <- this is
> probably waht you want
>
> Perhaps my problem raises from my lack of understanding of qml language
> and my mind working with pointers, references. Basically c/c++ like code.
>
> What I can't figure out here is how does one part of c++ code create a
> mapitem  object in qml; get a pointer to it in c++ which in turn passes
> that object to a geographical map inside another qml file. And then have
> the map display the mapitem as defined in the former qml file.
>
> I know I'm asking here to do my homework! But I'm really trying to
> understand how things work in the qml world. It took me several tries
> before I understood that I had to put that debug statement inside the
> oncompleted function for it to work. I still don't know how to dynamically
> change the plugin of the map (from c++) as I would like to have that choice
> made in a qwidget. I'm still learning...
>
> > Sent: Sunday, August 14, 2016 at 7:12 AM
> > From: "Kishore J" <kitts.mailinglists at gmail.com>
> > To: interest at qt-project.org
> > Subject: [Interest] Passing QML mapobjects (MapCircle) to QML maps
> through C++
> > Hi,
> >
> > Due to the lack of C++ API for maps, i am forced to use QML for the map
> but i am unable to understand how i need to structure my application.
> >
> > Architecturally, I have a qobject pool and various applications register
> objects to the pool. Any part of the application that can use the pooled
> object use it.
> >
> > In this scenario, i have some plugins that would pass map objects (or
> map object factories) to the pool. Then i have one or more maps that take
> the registered map object and show it on it's map.
> >
> > Since maps only work in QML, it is not clear to me how to achieve this.
> I have successfully created a MapWidget which basically
> inherits QQuickWidget along with a qml file that contains the following
> code.
> >
> > /**************************/
> > import QtQuick 2.5
> > import QtLocation 5.6
> >
> > Map {
> >     id: map
> >     zoomLevel: (maximumZoomLevel - minimumZoomLevel)/2
> >
> >     plugin: Plugin {
> >         name: "here"
> >         PluginParameter { name: "here.app_id"; value: "xxxxx" }
> >         PluginParameter { name: "here.token"; value: "xxxxx" }
> >     }
> >     activeMapType: supportedMapTypes[3]
> >
> >     MapCircle {
> >         id: circle
> >         center {
> >             latitude: 10
> >             longitude: 20
> >         }
> >         radius: 500.0
> >         color: 'black'
> >         opacity: .5
> >         border.width: 1
> >     }
> >
> >     Component.onCompleted:{
> >         for(var i = 0; i < supportedMapTypes.length; ++i)
> >             console.debug(i + ' ' + supportedMapTypes[i].name);
> >     }
> > }
> > /**************************/
> >
> > As such I have almost no experience with QML and getting the above QML
> file to work was a task in itself for me. I am comfortable with C++ side of
> things.
> >
> > I would really appreciate it if someone could hand hold me here. I
> understand that every MapObject that is created would need QML code again
> but I think i can deal with that. The map objects need not always be
> circles and could possibly be more complex qml code.
> > --
> > Regards,
> > Kishore
> >
> > _______________________________________________ Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
> _______________________________________________ Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160824/ad0ad9f2/attachment.html>


More information about the Interest mailing list