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

[SOLVED] the qt-way for creating sqlite-databases



  • Hello everyone,

    I started a small qt project and i am using the qt extensions only. I want to add a local database of type sqlite to my program. So far I got it working but I only know how to hack and create all tables and everything with the exec()-function.
    I have found wrappers for querys, databases-selection, select-calls of tables and so on, but no "qt-way" for creating the tables and key and so on. Is there no qt-support or functionality that helps with that instead of using plain exec-calls?

    Thanks for any help,

    Charmaman



  • You may execute queries to your database by using "QSqlQuery":http://qt-project.org/doc/qt-4.8/QSqlQuery.html. There is no better way that I know of. QSqlQuery provides you a very neat interface with bind parameters and everything you need.

    What do you expect to be the "qt-way" if not using queries to your database?



  • I expected something like the QDOM-style, where you create qdomelements and link them as you want and in the end you once do something like save() and it creates the whole xml-file...

    I guess I'll have to do it by hand then...



  • You might want to go through the "MVP":http://qt-project.org/doc/qt-4.8/model-view-programming.html as well.



  • Hi,
    Have a look at Predicate lib which has SQLite3 plugin: http://community.kde.org/Predicate

    It's Qt-only, LGPL, and unlike QtSQL it 'knows' how to create database and then new tables (has a Qt/C++ API for that). No need to pass SQL at all (but it can be if you wish). I am preparing this lib as a next get backend for Kexi and similar complex apps.

    The only downside - it's not yet released and its API isn't frozen, so you'd need a copy of it.



  • [quote author="jstaniek" date="1336511641"]Hi,
    Have a look at Predicate lib which has SQLite3 plugin: http://community.kde.org/Predicate

    It's Qt-only, LGPL, and unlike QtSQL it 'knows' how to create database and then new tables (has a Qt/C++ API for that). No need to pass SQL at all (but it can be if you wish). I am preparing this lib as a next get backend for Kexi and similar complex apps.

    The only downside - it's not yet released and its API isn't frozen, so you'd need a copy of it.[/quote]
    Thanks, this sounds like exactly what I have been looking for. Unfortunatly I'd prefer to avoid any dependencies (except Qt itself) as much as possible. I just hoped that there simply is a qt-api for my case that I simply couldn't find.
    I will accept that there is no api by qt, so I will do it by hand with SQL-commands.

    [quote author="Rahul Das" date="1336509988"]You might want to go through the "MVP":http://qt-project.org/doc/qt-4.8/model-view-programming.html as well.[/quote]
    I don't know what for since it doesn't have to do with my "problem".


Log in to reply