Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Integrating existing C++ into application and container for values [QML]

Integrating existing C++ into application and container for values [QML]

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
qml
5 Posts 2 Posters 776 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.
  • D Offline
    D Offline
    dmoviolin
    wrote on last edited by dmoviolin
    #1

    What I have: Existing C++ backend that works fine and it's ready to take file path and returns about 50 000 objects into vector, each object got some floats, enum simple stuff. Even got qmlRegisterType<MyType> ready. Also got QML application sceleton, it can open file, got row of data that works fine with obejcts MyTypeDraw, put some manually into row, got animation responses I want etc.
    What I do not know: 1 thing that I looked for hours(really), how do I take vector of MyClass in C++ and enter into program, furthermore since I work with large quantities I would like to have container to put them in order, I have not worked in js ever before, maybe there is container that I can use for that.

    DiracsbracketD 1 Reply Last reply
    0
    • D dmoviolin

      What I have: Existing C++ backend that works fine and it's ready to take file path and returns about 50 000 objects into vector, each object got some floats, enum simple stuff. Even got qmlRegisterType<MyType> ready. Also got QML application sceleton, it can open file, got row of data that works fine with obejcts MyTypeDraw, put some manually into row, got animation responses I want etc.
      What I do not know: 1 thing that I looked for hours(really), how do I take vector of MyClass in C++ and enter into program, furthermore since I work with large quantities I would like to have container to put them in order, I have not worked in js ever before, maybe there is container that I can use for that.

      DiracsbracketD Offline
      DiracsbracketD Offline
      Diracsbracket
      wrote on last edited by
      #2

      @dmoviolin said in Integrating existing C++ into application and container for values [QML]:

      how do I take vector of MyClass in C++ and enter into program, furthermore since I work with large quantities I would like to have container to put them in order

      Since you mention you want to organize your vector data in some way, maybe Instead of passing a vector from C++ to QML you could put all the data in a custom C++ model derived from QAbstractListModel, each model item corresponding to the instance of your C++ class you previously stored in a C++ vector.

      Then, you can pass the model to the QML context e.g using QQmlApplicationEngine::rootContext()->setContextProperty(...) which allows you to use the model in e.g. a ListView directly. If you want do sort/filter the model, you could also use an intermediate proxy model either in C++ via QSortFilterProxyModel or in QML using the DelegateModel type or the nice SortFilterProxyModel type https://github.com/oKcerG/SortFilterProxyModel.

      Of course, I have no idea if all that scales well for models with 50.000 items...

      1 Reply Last reply
      2
      • D Offline
        D Offline
        dmoviolin
        wrote on last edited by
        #3

        Thank you! I investigated QAbstractListModel and it's looking good, however I got another problem I didn't thought about, I got N rows where data needs to go, I successfully got data into 1 ListView, everything works fine, but how do I force it on N rows? Tried with row and repeaters but didn't work out. N is constant after loading data if that changes anything.

        DiracsbracketD 1 Reply Last reply
        0
        • D dmoviolin

          Thank you! I investigated QAbstractListModel and it's looking good, however I got another problem I didn't thought about, I got N rows where data needs to go, I successfully got data into 1 ListView, everything works fine, but how do I force it on N rows? Tried with row and repeaters but didn't work out. N is constant after loading data if that changes anything.

          DiracsbracketD Offline
          DiracsbracketD Offline
          Diracsbracket
          wrote on last edited by Diracsbracket
          #4

          @dmoviolin said in Integrating existing C++ into application and container for values [QML]:

          how do I force it on N rows?

          I'm not sure I understand what you mean.
          Do you mean you only see 1 delegate ? In that case, maybe the orientation of your listview is horizontal, but should be vertical?

          ListView {
             ...
             orientation: ListView.Vertical
          }
          

          Or do you mean you see M items, but want exactly N items? In that case you should adjust the dimensions of your ListView to be exactly N*yourDelegateHeight.

          1 Reply Last reply
          0
          • D Offline
            D Offline
            dmoviolin
            wrote on last edited by dmoviolin
            #5

            My data are in such way organized that there are N rows that needs to be displayed, I could use gridview to display it the way i need but it's bad idea IMO, cause they will change during program execution and I would display it like

            UPDATE:
            I used QAbstractTableModel,

            No idea how to delegate it so I get my row column structure.

            I guess what I am looking for is custom View for my model?
            What I got is NxN floats, lets say 3x3 float inside QAbstractTableModel and now looking for a way to put it into delegate, currently I can only display 1 row :/

            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