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



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



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



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



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



  • 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 :/


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.