Bonjour,

Je me connecte à une base SQLite mais à la compilation j'ai une erreur, en modifiant le code le problème vient de la méthode value de QsqlQuery. Je ne sait pas pourquoi il ne l'accepte pas.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <QtCore/QCoreApplication>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <string>
#include <iostream>
 
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
 
    QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName("C:/Documents and Settings/*****/Bureau/SQLite/test.sqlite");
    if (db.open())
        std::cout << "Connexion reussie." << std::endl;
    else
        std::cout << "Connexion echoue." << std::endl;
 
    QSqlQuery query;
    query.exec("SELECT col1, col2 FROM tabtest");
 
    while (query.next()) {
        int col1 = query.value(0).toInt();
        std::string col2 = query.value(1).toString();
        std::cout << col1 << " : " << col2 << std::endl;
    }
 
 
 
    system("pause");
 
    return a.exec();
}
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
main.cpp: In function `int main(int, char**)':
main.cpp:22: error: invalid use of undefined type `struct QVariant'
c:/Qt/qt/include/QtCore/../../src/corelib/kernel/qobject.h:65: error: forward declaration of `struct QVariant'
main.cpp:23: error: invalid use of undefined type `struct QVariant'
c:/Qt/qt/include/QtCore/../../src/corelib/kernel/qobject.h:65: error: forward declaration of `struct QVariant'