Results 1 to 3 of 3

Thread: invalid use of undefined type

  1. #1
    Join Date
    Apr 2006
    Location
    Erlangen, Germany
    Posts
    58
    Thanks
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default invalid use of undefined type

    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?

  2. #2
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: invalid use of undefined type

    Are you sure your file contains the correct include directive ( #include <QVariant> in that case)
    For less troubles with includes I suggest you do :

    Qt Code:
    1. //everywhere
    2. #include <QtCore>
    3.  
    4. //if gui used
    5. #include <QtGui>
    6.  
    7. //if SQL used
    8. #include <QtSql>
    9.  
    10. //and so on...
    To copy to clipboard, switch view to plain text mode 

    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...
    Last edited by fullmetalcoder; 9th April 2006 at 10:27.
    Current Qt projects : QCodeEdit, RotiDeCode

  3. #3
    Join Date
    Apr 2006
    Location
    Erlangen, Germany
    Posts
    58
    Thanks
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: invalid use of undefined type

    Quote Originally Posted by fullmetalcoder
    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 ;(

    Quote Originally Posted by fullmetalcoder
    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
    Qt Code:
    1. db = QSqlDatabase::addDatabase("QMYSQL");
    To copy to clipboard, switch view to plain text mode 
    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 ?
    Last edited by mikro; 9th April 2006 at 14:41.

Similar Threads

  1. QPSQL problem
    By LoneWolf in forum Installation and Deployment
    Replies: 60
    Last Post: 4th November 2009, 14:22
  2. problem with forward declaration
    By MarkoSan in forum General Programming
    Replies: 14
    Last Post: 6th January 2008, 21:45
  3. how to add static library into qmake
    By Namrata in forum Qt Tools
    Replies: 1
    Last Post: 20th November 2007, 17:33
  4. error undefined reference ...............
    By amit_pansuria in forum Qt Programming
    Replies: 2
    Last Post: 8th June 2007, 14:28
  5. how to correctly compile threads support?
    By srhlefty in forum Installation and Deployment
    Replies: 9
    Last Post: 25th June 2006, 19:15

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.