Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Switching from QWidgets to QML need advice

    General and Desktop
    3
    9
    1705
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      Marek last edited by A Former User

      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

      mrjj 1 Reply Last reply Reply Quote 0
      • mrjj
        mrjj Lifetime Qt Champion @Marek last edited by

        @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.

        https://qmlbook.github.io/

        1 Reply Last reply Reply Quote 1
        • M
          Marek last edited by

          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.

          1 Reply Last reply Reply Quote 0
          • ?
            A Former User last edited by

            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.

            1 Reply Last reply Reply Quote 2
            • M
              Marek last edited by Marek

              @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

              ? 1 Reply Last reply Reply Quote 0
              • ?
                A Former User @Marek last edited by

                @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 :)

                1 Reply Last reply Reply Quote 0
                • M
                  Marek last edited by

                  @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 ;)

                  ? mrjj 2 Replies Last reply Reply Quote 0
                  • ?
                    A Former User @Marek last edited by

                    @Marek said in Switching from QWidgets to QML need advice:

                    Best learning method in on a live project ;)

                    That's the spirit ;)

                    1 Reply Last reply Reply Quote 0
                    • mrjj
                      mrjj Lifetime Qt Champion @Marek last edited by

                      @Marek
                      Yes Learning by Doing is 100% the best way :)

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post