Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to combine QML and SQL conveniently?



  • I am working on a desktop program about SQL. But I find it is very inconvenient to interact with QML and SQL while it is much easier to use UI instead of QML. The examples about SQL in Qt Creator 3.3.0 are all written in either only C++ or combination of C++ and UI. I never saw SQL examples in QML and C++.

    Is QML not a good way to interact with Database?



  • @CoderJeff said:

    it is very inconvenient to interact with QML and SQL while it is much easier to use UI instead of QML

    Felt the same! may be because, too much used to UI than QML.
    Mean while i would like to share few links that was useful to me ..
    http://stackoverflow.com/questions/16658360/integrating-sqlite-with-qt-quick
    https://wiki.qt.io/How_to_use_a_QSqlQueryModel_in_QML
    http://wiki.qt.io/QML_and_QSqlTableModel



  • @Rahul-Das Thanks for your sharing. I also spent more time on the last two links.

    Besides, I think that the following links are also useful:
    http://doc.qt.io/qt-4.8/qtbinding.html
    http://doc.qt.io/qt-4.8/qml-integration.html

    "Keep in mind that QWidgets were designed for a different type of user interface than QML, so it is not always a good idea to port a QWidget-based application to QML. QWidgets are a better choice if your UI is comprised of a small number of complex and static elements, and QML is a better choice if your UI is comprised of a large number of simple and dynamic elements."

    "Warning: While it is possible to use C++ to access and manipulate QML objects deep into the object tree, we recommend that you do not take this approach outside of application testing and prototyping. One strength of QML and C++ integration is the ability to implement the QML user interface separately from the C++ logic and dataset backend, and this strategy breaks if the C++ side reaches deep into the QML components to manipulate them directly. This would make it difficult to, for example, swap a QML view component for another view, if the new component was missing a required objectName. It is better for the C++ implementation to know as little as possible about the QML user interface implementation and the composition of the QML object tree."



  • QxOrm library provides QxModelView module to interact easily between QML and database through the Qt model/view architecture.
    There is an example in the FAQ here : http://www.qxorm.com/qxorm_en/faq.html#faq_300


Log in to reply