tags:

views:

38

answers:

1

Just trying to mess around with Qt and SQLite to get familiar with how things work- I haven't really done DB programming since my vb6 days, so please be easy ;]

I'm just trying to get the result of a query and I'm trying to follow some examples I found online (namely this one). The process seems simple enough: create the QSqlQuery object, have it execute a query, check that something came back, and just get the value. When doing this, I'm getting an error. Code follows:

bool DatabaseManager::structureDB(){
    QSqlQuery query;
    query.exec("CREATE TABLE mytable"
                      " (id integer primary key,"
                      " firstname varchar(20),"
                      " lastname varchar(20),"
                      " age integer)");

    QSqlQuery query2;
    query2.exec("pragma table_info(mytable)");

    if(query2.first()){
        QString test = query2.value(0).toString(); // Error line
        qDebug()<<test;
        return true;
    }
    return false;
}

The error I am getting is:

error: invalid use of incomplete type 'struct QVariant'

On the line commented above. I'm not sure what this error means or what I'm doing wrong, can someone please help? Thanks so much!

+1  A: 

Basically, the type is declared but not defined, like this:

struct QVariant;

Once you try to use it, it needs to be defined, like this:

struct QVariant
{
    // stuff goes here
};

The error is telling you it's incomplete (declared but not defined), and therefore not usable. You should include the header <QVariant> to get the definition of QVariant, to make it complete and therefore usable.

GMan
[Boom](http://imgur.com/f3b7Z.jpg), binary cupcakes!
Airjoe