[Qt-qml] How to interface between main.cpp classes and custom c++ based widgets?

Till Harbaum / Lists lists at harbaum.org
Mon Jul 11 21:28:06 CEST 2011


Hi,

i am porting the UI of my cacheme application to qml. Most things somehow work, some even nicely (making map overlays
is a snap) and some are rather tricky (a nice file selector). But there is one thing i can't figure out how to do correctly:

I have a widget which is a ggraphicsgeomap. This widget of course needs to interface to various things like the
gps. My original plain qt had a global instance of my locationProvider class and i connected this to a slot in my mapwidget instance.

But how do i do that with qml in between? My main.cpp contains an instance of my locationProvider, so i need a connect
my custom widget with the instance only known to my main function. I think one step is to register my locationProvider with the
declarative view:

  LocationProvider locationProvider;
  view.rootContext()->setContextProperty("LocationProvider", &locationProvider);

in my qml part i create an instance of my map class  (my map is registered in c++ via 
qmlRegisterType<MapWidget>("MapWidget", 1, 0, "Map"), so the widget is created this way:

 Map {
   id: map
 }

Now the question: How do i connect a signal from my locationProvider with a slot of my map?

Regards,
  Till


More information about the Qt-qml mailing list