Important: Please read the Qt Code of Conduct -

Universal return from SQLite to QML. How?

  • Hello all!

    In this example the interaction between SQLite and QML via defining data model/roles hardly in listmodel.cpp:

    QHash<int, QByteArray> ListModel::roleNames() const {
    	QHash<int, QByteArray> roles;
    	roles[IdRole] = "id";
    	roles[FNameRole] = "fname";
    	roles[SNameRole] = "sname";
    	roles[NikRole] = "nik";
    	return roles;

    Is there any way to return the data like array independently of data structure. And handling data in QML/Js without defining it in CPP? If there 5 fields in DB row - then return array within 5 elements, if there 10 fields in row then return array of 10 elements. I need to create tables dynamically on runtime and perform CRUD (Create/Read/Update/Delete) operations.

  • Lifetime Qt Champion


    Do you have some kind of REST service in mind ?

  • @SGaist Do you have any suggestion for the matter of this topic? How REST might be connected to the topic? CRUD is only acronym that mean operations ability not only for REST API.

    For now I am seeking solution to perform the line:

    direct schema: [something from SQL query based on Sqlite] ->> QVariantList ->> JS Array in QML
    reverse schema: JS Array in QML ->> QVariantList ->> [something to SQL query based on Sqlite]

    The question about "something from/to SQL query based on Sqlite" where I don't need to be hardcoded the data model. I need to do it dynamically. I shouldn't care about data model on CPP level only in QML/JS, just passing query result as-it-is into QML like JS Array. Nothing more.

  • Lifetime Qt Champion

    I know what CRUD means. Lately I've encountered it more in the context of web service than anything else, hence my question.

    From the looks of it, you seem to want to write some sort of alternative to phpMyAdmin in QML. Is that the case ?

Log in to reply