QSql - incomplete type 'struct QVariant'
Spent all day Friday and today looking at examples and can't spot what I'm doing wrong. Based on the error I feel like it's got to be something fundamental. I've reproduced the error below.
Code:
#include <QtCore/QCoreApplication>
#include <QSqlDatabase>
#include <QSqlError>
#include <QSqlQuery>
#include <QDir>
#include <QFile>
#include <QDebug>
int main(int argc, char *argv[])
{
bool ret=false;
strDBFile.
append(QDir::separator()).
append("my.db.sqlite");
strDBFile
= QDir::toNativeSeparators(strDBFile
);
db.setDatabaseName(strDBFile);
if(db.isOpen())
{
ret=q.exec("create table WTF(ID INT, NAME VARCHAR(20))");
if(ret)
{
ret=q.exec("insert into WTF values(1, 'your mom')");
if(ret)
{
q.exec("select * from WTF;");
if(q.next())
{
qDebug()<<q.value(0).toString();
}
}
}
}
return a.exec();
}
Code:
C:/Documents and Settings/ald/My Documents/SQLStub/SQLStub-build-desktop/../SQLStub/main.cpp:36: error: invalid use of incomplete type 'struct QVariant'
c:\Qt\2010.04\qt\include/QtCore/../../src/corelib/kernel/qobject.h:66: error: forward declaration of 'struct QVariant'
Re: QSql - incomplete type 'struct QVariant'
Quote:
Originally Posted by
UltramaticOrange
Code:
C:/Documents and Settings/ald/My Documents/SQLStub/SQLStub-build-desktop/../SQLStub/main.cpp:36: error: invalid use of incomplete type 'struct QVariant'
c:\Qt\2010.04\qt\include/QtCore/../../src/corelib/kernel/qobject.h:66: error: forward declaration of 'struct QVariant'
You need to add
Code:
#include <QVariant>
I think, it is better to create QSqlQuery object after opening database connection.
Re: QSql - incomplete type 'struct QVariant'
Like I said, missing something fundamental. Thanks. I'm going to go /headdesk in the corner now.
QSqlQuery is defined with a much more narrow scope (and after db is opened) in the real application.