Switching from QWidgets to QML need advice
-
Hi
I need to implement map & navigation into my QWidgets based app. I have created new QMainWindow in which i placed QQuickWidget widget and generally everything works, I can see map, add wayPoints, get coordinates, GeocodeModel, RouteModel, set QML properties from C++ and call C++ functions from QML.
I need some more flexibility though and I'm new to QML. So I will explain what I would have done in QWidgets/C++ and need someone to advice how to translate this to QML, what QML object to use for display and data handling.So I would pass pointer to my class wayPointMgr to map manager, I would create some structure and QMap<int,WayPointData*> to handle data and display this in QListWidget (in map manager). When I select some item from the view I know by SIGNAL/SLOT connection which point I'm currently modifying and set some member variable like "int currWayPoint" that is also a key to QMap. I also need InternalMove property inside QListWidget to be set. I can add new objects by creating new WayPointData struct and add this to QMap and QListWidget. After everything is done I'm calling wayPointMgr->clear() and from QMapIterator I'm settings wayPointMgr->addPoint(some_data).
So the biggest problem is actually how to handle data in QML where I don't have any class, member variables or struct and QMap ?Best Regards
Marek -
Hi
I need to implement map & navigation into my QWidgets based app. I have created new QMainWindow in which i placed QQuickWidget widget and generally everything works, I can see map, add wayPoints, get coordinates, GeocodeModel, RouteModel, set QML properties from C++ and call C++ functions from QML.
I need some more flexibility though and I'm new to QML. So I will explain what I would have done in QWidgets/C++ and need someone to advice how to translate this to QML, what QML object to use for display and data handling.So I would pass pointer to my class wayPointMgr to map manager, I would create some structure and QMap<int,WayPointData*> to handle data and display this in QListWidget (in map manager). When I select some item from the view I know by SIGNAL/SLOT connection which point I'm currently modifying and set some member variable like "int currWayPoint" that is also a key to QMap. I also need InternalMove property inside QListWidget to be set. I can add new objects by creating new WayPointData struct and add this to QMap and QListWidget. After everything is done I'm calling wayPointMgr->clear() and from QMapIterator I'm settings wayPointMgr->addPoint(some_data).
So the biggest problem is actually how to handle data in QML where I don't have any class, member variables or struct and QMap ?Best Regards
Marek@Marek said in switching from QWidgets to QML need advice:
So the biggest problem is actually how to handle data in QML where I don't have any class, member variables or struct and QMap ?
Well its actual the normal way. QML for display, c++ for processing.
http://doc.qt.io/qt-5/qtqml-cppintegration-data.html
You would then export the c++ data to QML.
-
thanks for first link, second one I have browsed earlier, but seems incomplete, I mean simple things are explained but more difficult often marked as TODO.
I have moved all my buttons, listView and text inputs from QML to QWidget part and now QQuickWidget is only displaying map and mapItems, and now I'm dabbling with javascript. Maybe later when this all will work I will move controls to QML.
-
Hi! I'd recommend to read Models and Views in Qt Quick and Using C++ Models with Qt Quick Views first. You'll see that using a model and a view instead of a list widget and stuff, will greatly simplify your implementation.
-
@Wieland
I thought about this but my model data is not static I need to add and remove points from map.
Can I modify model in QML add and remove data?
Model must also be created dynamically, otherwise I would have to use C++ Models and setProperty, I mean export model to QML -
@Wieland
I thought about this but my model data is not static I need to add and remove points from map.
Can I modify model in QML add and remove data?
Model must also be created dynamically, otherwise I would have to use C++ Models and setProperty, I mean export model to QML@Marek said in Switching from QWidgets to QML need advice:
Can I modify model in QML add and remove data?
Yes, that's the whole point of it :)
-
@Wieland
OK, one step at the time, there is a lot I don't know about this QML and as usual I need this app fast ;)
For now it will work with data and controls in C++ and map i QML - almost ready
Best learning method in on a live project ;)@Marek said in Switching from QWidgets to QML need advice:
Best learning method in on a live project ;)
That's the spirit ;)
-
@Wieland
OK, one step at the time, there is a lot I don't know about this QML and as usual I need this app fast ;)
For now it will work with data and controls in C++ and map i QML - almost ready
Best learning method in on a live project ;)