PDA

View Full Version : QSql - incomplete type 'struct QVariant'



UltramaticOrange
4th October 2010, 22:45
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.


#include <QtCore/QCoreApplication>
#include <QSqlDatabase>
#include <QSqlError>
#include <QSqlQuery>
#include <QDir>
#include <QFile>
#include <QDebug>

int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);

QSqlQuery q;
bool ret=false;

QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");

QString strDBFile(QDir::home().path());
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();
}


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'

saa7_go
5th October 2010, 04:36
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

#include <QVariant>

I think, it is better to create QSqlQuery object after opening database connection.

UltramaticOrange
5th October 2010, 19:07
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.