Please use the [CODE] tags, it's hard to read your code now.
You have to assign the database to query, it won't work otherwise:
Qt Code:
  1. QSqlQuery query("SELECT * FROM City", db);
  2. // or
  3. QSqlQuery query(db);
  4. query.prepare("SELECT * FROM City");
To copy to clipboard, switch view to plain text mode