Evgenii Legotckoi
Nov. 20, 2015, 9:23 p.m.

Qt/C++ - Lesson 040. Types of data in different Databases in Qt

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)
BIT Boolean BOOL
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

Result

As a result of the type of DECIMAL was simply changed to INTEGER type, and everything works.

Do you like it? Share on social networks!

Comments

Only authorized users can post comments.
Please, Log in or Sign up
  • Last comments
  • AK
    April 1, 2025, 11:41 a.m.
    Добрый день. В данный момент работаю над проектом, где необходимо выводить звук из программы в определенное аудиоустройство (колонки, наушники, виртуальный кабель и т.д). Пишу на Qt5.12.12 поско…
  • Evgenii Legotckoi
    March 9, 2025, 9:02 p.m.
    К сожалению, я этого подсказать не могу, поскольку у меня нет необходимости в обходе блокировок и т.д. Поэтому я и не задавался решением этой проблемы. Ну выглядит так, что вам действитель…
  • VP
    March 9, 2025, 4:14 p.m.
    Здравствуйте! Я устанавливал Qt6 из исходников а также Qt Creator по отдельности. Все компоненты, связанные с разработкой для Android, установлены. Кроме одного... Когда пытаюсь скомпилиров…
  • ИМ
    Nov. 22, 2024, 9:51 p.m.
    Добрый вечер Евгений! Я сделал себе авторизацию аналогичную вашей, все работает, кроме возврата к предидущей странице. Редеректит всегда на главную, хотя в логах сервера вижу запросы на правильн…
  • Evgenii Legotckoi
    Oct. 31, 2024, 11:37 p.m.
    Добрый день. Да, можно. Либо через такие же плагины, либо с постобработкой через python библиотеку Beautiful Soup