Hi all,

I tried to run an app with QPSQL, but I found that it doesn't support UNICODE:

qt1.png

and from psql shell:

postgresql2.png

I inserted first row with psql shell therefore you can see unicode is supported inside postgresql.
As postgresql docs says (link):

"Programs using libpq directly need to be aware of this, but not much else does."
So I'm trying to run a test app with QODBC, even if qt docs says that it's better to use specific driver (QPSQL) link:
Note: You should use native drivers in preference to the ODBC driver where they are available. ODBC support can be used as a fallback for compliant databases if no native drivers are available.
I installed driver manager too (following this thread instructions):
posgresql1.png

then compiled and installed qt odbc wrapper:
qt0.jpg

this is my code:


Qt Code:
  1. //main.cpp:
  2. #include <QCoreApplication>
  3. #include <QSqlRecord>
  4. #include <QSqlQuery>
  5. #include <QSqlError>
  6. #include <QSqlDriver>
  7. #include <QDebug>
  8.  
  9. class Database
  10. {
  11. public:
  12. explicit Database();
  13. ~Database();
  14. bool connection();
  15. private:
  16. QString driverName;
  17. };
  18.  
  19. Database::~Database()
  20. {
  21. db.close();
  22. }
  23.  
  24. Database::Database() :
  25. db(QSqlDatabase::addDatabase("QODBC"))
  26. //db(QSqlDatabase::addDatabase("QODBC3"))//tried even with this
  27. {
  28. driverName = QString("QODBC");
  29. db.setDatabaseName("Driver={PostgreSQL};Server=localhost;Port=5432;Database=prova;Uid=postgres;Pwd=*******;");
  30. //db.setConnectOptions("SQL_ATTR_ODBC_VERSION=SQL_OV_ODBC3");//tried even with this
  31. }
  32.  
  33. bool Database::connection()
  34. {
  35. if (!db.open()) {
  36. qDebug() << QString("Unable to establish a database connection.\n"
  37. "This example needs %1 support. Please read "
  38. "the Qt SQL driver documentation for information how "
  39. "to build it.\n\n"
  40. "Click Cancel to exit.").arg(driverName);
  41. return false;
  42. }
  43. return true;
  44. }
  45.  
  46. bool insertTest()
  47. {
  48. q.prepare("INSERT INTO p(d) VALUES(:d)");
  49. q.bindValue(":d",QString("Questa è un altra prova"));
  50. return q.exec();
  51. }
  52.  
  53. int main(int argc, char **argv)
  54. {
  55. QCoreApplication app(argc,argv);
  56. const QScopedPointer<Database> database(new Database());
  57. database->connection();
  58. if(insertTest())
  59. {
  60. qDebug() << "query executed successfully";
  61. }else{
  62. qDebug() << "insert query error";
  63. }
  64. q.exec("SELECT * FROM p");
  65. while(q.next())
  66. {
  67. QSqlRecord r = q.record();
  68. qDebug() << "id=" << r.value("id").toInt();
  69. qDebug() << "d=" << r.value("d").toString() << '\n';
  70. }
  71. return app.exec();
  72. }
To copy to clipboard, switch view to plain text mode 

and this is my .pro file:
Qt Code:
  1. QT += core gui sql widgets
  2. TARGET = ScopedPointer
  3. CONFIG += console
  4. TEMPLATE = app
  5.  
  6. sql-plugins += odbc
  7.  
  8. SOURCES += main3.cpp
  9.  
  10. OBJECTS_DIR = build/o
  11. MOC_DIR = build/moc
  12. UI_DIR = build/ui
  13. RCC_DIR = build/rcc
  14. DESTDIR = bin
To copy to clipboard, switch view to plain text mode 
I added sql-plugins directive following this thread

Anyway i get this error message:
Qt Code:
  1. "QODBCResult::exec: No statement handle available" Error: "[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified"
To copy to clipboard, switch view to plain text mode 

as you can see here:
error.png

I'm using Qt 5.2.0. If you need any other information please ask.
Any help would be appreciated, thanks!
Alberto