Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Switching from QWidgets to QML need advice

Switching from QWidgets to QML need advice

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 3 Posters 2.1k Views
  • 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 Offline
    M Offline
    Marek
    wrote on last edited by A Former User
    #1

    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

    mrjjM 1 Reply Last reply
    0
    • M 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

      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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
      1
      • M Offline
        M Offline
        Marek
        wrote on last edited by
        #3

        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
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          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
          2
          • M Offline
            M Offline
            Marek
            wrote on last edited by Marek
            #5

            @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
            0
            • M 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

              ? Offline
              ? Offline
              A Former User
              wrote on last edited by
              #6

              @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
              0
              • M Offline
                M Offline
                Marek
                wrote on last edited by
                #7

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

                ? mrjjM 2 Replies Last reply
                0
                • M Marek

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

                  ? Offline
                  ? Offline
                  A Former User
                  wrote on last edited by
                  #8

                  @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
                  0
                  • M Marek

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

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

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

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved