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

DECIMAL, INTEGER, MS SQL, Qt, SQL, типы данных

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


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

We recommend hosting TIMEWEB
We recommend hosting TIMEWEB
Stable hosting, on which the social network EVILEG is located. For projects on Django we recommend VDS hosting.
Support the author Donate


Only authorized users can post comments.
Please, Log in or Sign up

Hello, Dear Users of EVILEG!!!

If the site helped you, then support the development of the site financially, please.

You can do it by following ways:

Thank you, Evgenii Legotckoi

Dec. 13, 2019, 6:05 a.m.
Aruzhan Seraliyeva

C++ - Тест 003. Условия и циклы

  • Result:50points,
  • Rating points-4
Dec. 13, 2019, 5:47 a.m.
Aruzhan Seraliyeva

C++ - Test 001. The first program and data types

  • Result:40points,
  • Rating points-8
Dec. 11, 2019, 4:56 p.m.

C++ - Тест 003. Условия и циклы

  • Result:50points,
  • Rating points-4
Last comments
Dec. 9, 2019, 3:41 a.m.
Evgenij Legotskoj

Эта ошибка invalid use of incomplete type ‘class Ui::AnotherWindow’ обычно говорит о том, что не найдено определение класса или структуры. Типичная проблема - не подключён заголовочны…
Dec. 9, 2019, 3:36 a.m.
Nikolaj Batmanov

Ну, не настолько со мной всё полхо...))) Вроде бы. Я ж кнопки отрисовываю.
Dec. 9, 2019, 3:14 a.m.
Evgenij Legotskoj

Добрый день. У вас ui файлов по ходу нет. UI файлы используются для вёрстки в графическом дизайнере.
Dec. 9, 2019, 3:05 a.m.
Nikolaj Batmanov

Здравствуйте! Полностью скопировал ваш пример к себе, чтобы разобраться. А он не хочет запускаться, дает ошибку: invalid use of incomplete type ‘class Ui::AnotherWindow’ ui(new Ui…
Dec. 8, 2019, 7:23 a.m.
Evgenij Legotskoj

У меня здесь есть одна старая статья с примером векторного редактора. Там есть ответы на ваши вопросы. Поизучайте Qt/C++ - Урок 072. Пример векторного редактора на Qt QGraphicsItem, QG…
Now discuss on the forum
Dec. 13, 2019, 10:16 a.m.
Ruslan Volshebnik

Да, я посмотрел, вы абсолютно правы. Единственное, если я правильно понял, если срабатывает условие if (aggregates["max_id"] - aggregates["min_id"]) + 1 == aggregates["count"]: return sel…
Dec. 13, 2019, 9:53 a.m.

Ответ >>
Dec. 13, 2019, 8:39 a.m.
Aleksandr Panjushkin

Вроде да. Только там начинаются вопросы с тем, чтобы виджет бы в фокусе, чтобы до виджета это событие долетало.
Dec. 13, 2019, 7:48 a.m.
Dzhon Kofi

Привет. Есть класс "ждун", который используется на разных виджетах: class WaiterDialog;#define WAITER_DIALOG Singleton<WaiterDialog>::instance()class WaiterDialog : public QObject, …
© EVILEG 2015-2019
Recommend hosting TIMEWEB