In the process of application development for Qt, which will have to work with databases, you must take into account the nuance that Qt driver target Databases may not support all types of data that you can lay in your database. For example, one such example, which faced one of the Readers site, this is the problem with data type mapping DECIMAL through QSqlTableModel . At that time, both in the development of applications in the C++ Builder, this type of data displayed in the fine.
And the work was done with the database MS SQL database for which an ODBC driver used. The results of the applications on C ++ Builder and Qt are shown in the following figures. The difference in the external tables, as is that in Qt applications are no values in the view, where the type of data in the database has been declared as DECIMAL .
Application on the C ++ Builder - All columns are filled
Application on Qt - no values in columns of type DECIMAL data
Check the types of data in the documentation
When checking the supported types of data on a page in the official documents we find data types that are supported by selected driver and adjust the database according to the data types that are supported by this same driver.
ODBC Data Types
|ODBC data type||SQL type description||Recommended input (C++ or Qt data type)|
|TINYINT||8 bit integer||typedef qint8|
|SMALLINT||16-bit signed integer||typedef qint16|
|INTEGER||32-bit signed integer||typedef qint32|
|BIGINT||64-bit signed integer||typedef qint64|
|REAL||32-bit Single-precision floating point||By default mapping to QString|
|FLOAT||64-bit Double floating point||By default mapping to QString|
|DOUBLE||64-bit Double floating point||By default mapping to QString|
|CHAR||Character string||Mapped to QString|
|VARCHAR||Character string||Mapped to QString|
|LONGVARCHAR||Character string||Mapped to QString|
|CLOB||Character large string object||Mapped to QString|
|DATE||Character string||Mapped to QDate|
|TIME||Character Time, Character string||Mapped to QTime|
|TIMESTAMP||Character Time, Character string||Mapped to QDateTime|
As a result of the type of DECIMAL was simply changed to INTEGER type, and everything works.