Results 1 to 3 of 3

Thread: QSql - incomplete type 'struct QVariant'

  1. #1
    Join Date
    Oct 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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.

    Qt Code:
    1. #include <QtCore/QCoreApplication>
    2. #include <QSqlDatabase>
    3. #include <QSqlError>
    4. #include <QSqlQuery>
    5. #include <QDir>
    6. #include <QFile>
    7. #include <QDebug>
    8.  
    9. int main(int argc, char *argv[])
    10. {
    11. QCoreApplication a(argc, argv);
    12.  
    13. bool ret=false;
    14.  
    15. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    16.  
    17. QString strDBFile(QDir::home().path());
    18. strDBFile.append(QDir::separator()).append("my.db.sqlite");
    19. strDBFile = QDir::toNativeSeparators(strDBFile);
    20. db.setDatabaseName(strDBFile);
    21.  
    22. if(db.isOpen())
    23. {
    24. ret=q.exec("create table WTF(ID INT, NAME VARCHAR(20))");
    25. if(ret)
    26. {
    27. ret=q.exec("insert into WTF values(1, 'your mom')");
    28.  
    29. if(ret)
    30. {
    31. q.exec("select * from WTF;");
    32.  
    33. if(q.next())
    34. {
    35. qDebug()<<q.value(0).toString();
    36. }
    37. }
    38. }
    39. }
    40.  
    41. return a.exec();
    42. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. C:/Documents and Settings/ald/My Documents/SQLStub/SQLStub-build-desktop/../SQLStub/main.cpp:36: error: invalid use of incomplete type 'struct QVariant'
    2.  
    3. c:\Qt\2010.04\qt\include/QtCore/../../src/corelib/kernel/qobject.h:66: error: forward declaration of 'struct QVariant'
    To copy to clipboard, switch view to plain text mode 
    Last edited by UltramaticOrange; 4th October 2010 at 23:05.

  2. #2
    Join Date
    Jun 2010
    Location
    Salatiga, Indonesia
    Posts
    160
    Thanks
    11
    Thanked 32 Times in 29 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    1

    Default Re: QSql - incomplete type 'struct QVariant'

    Quote Originally Posted by UltramaticOrange View Post

    Qt Code:
    1. C:/Documents and Settings/ald/My Documents/SQLStub/SQLStub-build-desktop/../SQLStub/main.cpp:36: error: invalid use of incomplete type 'struct QVariant'
    2.  
    3. c:\Qt\2010.04\qt\include/QtCore/../../src/corelib/kernel/qobject.h:66: error: forward declaration of 'struct QVariant'
    To copy to clipboard, switch view to plain text mode 
    You need to add
    Qt Code:
    1. #include <QVariant>
    To copy to clipboard, switch view to plain text mode 

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

  3. #3
    Join Date
    Oct 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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.

Similar Threads

  1. incomplete type?
    By T0bi4s in forum General Programming
    Replies: 6
    Last Post: 11th February 2019, 07:02
  2. error: invalid use of incomplete type 'struct QMetaEnum'
    By dyngoman in forum Qt Programming
    Replies: 3
    Last Post: 12th March 2010, 13:38
  3. Replies: 4
    Last Post: 12th October 2009, 19:36
  4. QApplication::desktop() incomplete type
    By codebehind in forum Newbie
    Replies: 7
    Last Post: 21st August 2008, 19:08
  5. Replies: 3
    Last Post: 4th August 2006, 12:05

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.