0

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!

2
  • Is QVariant defined? (Have you included its header?) Commented Jul 23, 2010 at 0:18
  • I did not include it, I have included <QSqlQuery>. Including <QVariant> seems to have done the trick, thanks! If you submit a formal answer I'll select it as correct, I think you get a cupcake or something if you answer correctly! Commented Jul 23, 2010 at 0:30

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.