Results 1 to 11 of 11

Thread: Trying to learn. Not declared in this scope error

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2010
    Posts
    107
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Trying to learn. Not declared in this scope error

    What do I need to do to have the connection and queries in the header file? If put the function in to test if the mxtrainer is there to see if it is the first time the program has run. If it is the first time, create the table. If not use the existing data. Where is the tool for single stepping through the code...I have been using breakpoints to try and find the problems. I got rid of the test and put in QSqlQuery::Last error like this:
    Qt Code:
    1. void createDb()
    2. {
    3. QSqlQuery query;
    4. //query.exec("DROP TABLE scooter");
    5.  
    6. query.exec("CREATE TABLE rider ("
    7. "id INTEGER PRIMARY KEY AUTOINCREMENT, "
    8. "name VARCHAR(20) NOT NULL, "
    9. "weight INTEGER NOT NULL, ");
    10. query.exec("INSERT INTO rider (name, weight) "
    11. "VALUES ('Villapoto', 155");
    12. query.exec("INSERT INTO rider (name, weight) "
    13. "VALUES ('Carmichael', 165");
    14. query.exec("INSERT INTO rider (name, weight) "
    15. "VALUES ('McGrath', 175");
    16. qDebug() << query.lastError();
    17. }
    18. int main(int argc, char *argv[])
    19. {
    20. QApplication a(argc, argv);
    21. //bool create = !QFile::exists("mxtrainer.dat");
    22. //if (!createConnection())
    23. //return 1;
    24. //if (create)
    25. createDb();
    26. MXMainWindow w;
    27. w.show();
    28.  
    29. return a.exec();
    30. }
    To copy to clipboard, switch view to plain text mode 
    I got an error database not open.
    Where do I go from here?
    PS. I really appreciate all your help!!

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Trying to learn. Not declared in this scope error

    The "Database not open error" is the result of commenting out the createConnection() call, which is opening the database! In your previous attempt the error you would be really interested in was the exec() call after trying to select the rider's names.

    The debugging tool you are setting breakpoints in can single-step your program. Look on the Debug menu in Qt Creator when you are stopped at a break point.

    I don't know exactly what you mean by "What do I need to do to have the connection and queries in the header file?". You just put the code there and make sure it is included where required. However, it is usually not a good idea to put real implementation code into header files (with the exception of trivial inline methods). The Qt examples do this to simplify the construction of many independent programs that use that example database. Headers are typically expected to contain declarations only, with the implementation (if any) in a matching cpp file.

  3. #3
    Join Date
    Aug 2010
    Posts
    107
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Trying to learn. Not declared in this scope error

    I uncommented out that section and got the error QSqlError(1, "Unable to execute statement", "near "175": syntax error") And stepping in goes through the QT code. Am I missing something?
    And when I put in after the Select name query I got: QSqlError(-1, "Unable to fetch row", "No query")
    Last edited by poporacer; 21st September 2010 at 06:05. Reason: more info

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Trying to learn. Not declared in this scope error

    Your SQL INSERT statements are malformed: missing their closing )

    Edit: So is your create table.

  5. #5
    Join Date
    Aug 2010
    Posts
    107
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Trying to learn. Not declared in this scope error

    Thank you so much...I am starting to figure this out a little bit at a time. I really appreciate your help!
    The program works and the combo box gets populated, but in the QSqlError message I get
    QSqlError(-1, "", "")
    QSqlError(-1, "", "")
    I couldn't find any reference to what the -1 or the "","" errors are. Any Ideas?
    Last edited by poporacer; 22nd September 2010 at 01:15. Reason: updated contents

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Trying to learn. Not declared in this scope error

    I think (not near a machine to test) that QSqlError::isValid() would return false... no error.

  7. #7
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Trying to learn. Not declared in this scope error

    Quote Originally Posted by ChrisW67 View Post
    I think (not near a machine to test) that QSqlError::isValid() would return false... no error.
    You are right, -1 indicates that there is no error. To see if a statement was successful fetch the result of QSqlQuery::exec()

Similar Threads

  1. Replies: 2
    Last Post: 16th July 2010, 07:17
  2. QDomDocument was not declared in this scope
    By grantbj74 in forum Newbie
    Replies: 5
    Last Post: 25th August 2009, 09:43
  3. glutSolidSphere was not declared in this scope error
    By nuts_fever_007 in forum Qt Programming
    Replies: 2
    Last Post: 15th May 2009, 04:56
  4. Replies: 2
    Last Post: 28th December 2007, 18:30
  5. error: 'connect' was not declared in this scope ??
    By Morea in forum Qt Programming
    Replies: 2
    Last Post: 14th January 2007, 15:27

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
  •  
Qt is a trademark of The Qt Company.