Home > Software engineering >  How to get all values in SQL from a table's column, in QT C
How to get all values in SQL from a table's column, in QT C

Time:12-18

So I'm trying to get all of the values from a sqlite3 database in QT with C (11). My table called "Auteurs", and the column that contains all the values called "nom".

The Whole table looks like this:

enter image description here

With DB Browser I successfully extracted all the values but implementing it into my program that accepted the the following syntax :

Etudiants->exec(QLatin1String("SELECT nom FROM Auteurs WHERE nom is not NULL"));

this only returns me the first value (in a form of QVariant) of the table and not the rest as well. Any suggestion how to get all the values out and not just 1 from the table at a time? In what sort of type I should store the values, that I will get (QStringList or something else)?

Other useful indications : Qt 5.14.1 (i386-little_endian-ilp32 shared (dynamic) release build;

by MSVC 2017) on "windows" OS: Windows 8.1 Version 6.3 (Build 9600) [winnt version 6.3.9600]

Architecture: x86_64;

Thank you for your help !

CodePudding user response:

Okay so I found the solution on my own. All I had to do after executing Etudiants->exec(QLatin1String("SELECT nom FROM Auteurs WHERE nom is not NULL")); is, do a loop with Etudiants->next(); in which i do each time a Etudiants->value(0).toString(); which i can simply store in a QStringList.

  • Related