PDA

View Full Version : invalid use of undefined type



mikro
9th April 2006, 10:14
hi,
i am trying to get the result of a query.the databaseconnection seems to work, then i do:
QSqlQuery query("SELECT s2 FROM test", db);
while (query.next())
{
Beschriftung = query.value(0).toString();
}

compiler tells me:
invalid use of undefined type 'struct QVariant'
for the line where i try get the query value. (Beschriftung has been declared as QString further up).

From the docs i understand that query.value(0) will be variant, but i thought with the toString() i get a string and can put it into Beschriftung? After all this line is more or less directly from the doc

oh, btw: i wanted to check if db isn't by some chance out of scope. it's been some time that i learned some c and i am now just trying to remember. For the last years i have only been scripting in php, so i tried:
if (!db)
if (db == false)
but nothing works. the last line gives me a compilererror of
no match for 'operator==' in 'db == false'

what is that suppossed to mean?

fullmetalcoder
9th April 2006, 10:21
Are you sure your file contains the correct include directive ( #include <QVariant> in that case)
For less troubles with includes I suggest you do :



//everywhere
#include <QtCore>

//if gui used
#include <QtGui>

//if SQL used
#include <QtSql>

//and so on...




oh, btw: i wanted to check if db isn't by some chance out of scope. it's been some time that i learned some c and i am now just trying to remember. For the last years i have only been scripting in php, so i tried:
if (!db)
if (db == false)
but nothing works. the last line gives me a compilererror of
no match for 'operator==' in 'db == false'

what is that suppossed to mean?


It just means that Qt doesn't offer any overload of operator '==' for QSqlDatabase class. AFAIK a database can never be out of scope by itslef so your test is quite meaningless. 'if ( !db ) can be usefull to detect wether a pointer is initialized or not but your 'db' variable doesn't seem to be a pointer...

mikro
9th April 2006, 12:10
Are you sure your file contains the correct include directive ( #include <QVariant> in that case)
For less troubles with includes I suggest you do :


ok, sorry, i found out, that my problems were simply based on the fact, that i was not using qmake but compiled directly.
so now i will have to find out how to make Code::Blocks use qmake or compile by hand ;(


It just means that Qt doesn't offer any overload of operator '==' for QSqlDatabase class. AFAIK a database can never be out of scope by itslef so your test is quite meaningless. 'if ( !db ) can be usefull to detect wether a pointer is initialized or not but your 'db' variable doesn't seem to be a pointer... no, it isn't. it has been created with

db = QSqlDatabase::addDatabase("QMYSQL");
but this line is within a function in the headerfile. i declared the variable in my main.cpp before including this header file, so i assume the variable should be in scope. nevertheless i'd like to check if it is and contains a databaseconnection. as it has been declared to be of type QSqlDatabase checking for type is useless i assume. This is why i tought i could test for NULL or empty ?