Advanced search

Qt

Aug. 17, 2015, 2:55 a.m.

QSqlQueryModel, qsqlquerymodel example, qt, qt таблицы, query

Using QSqlQueryModel to form tables in Qt is the most hardcore version with the lowest level of abstraction than the use QSqlTableModel or QSqlRelationalTableModel . But with all this, and the most flexible option, which requires a deeper knowledge of the language of SQL-queries. In a previous article , two tables were constructed:

  • The main, which were columns Дата, Время, Имя Хоста, IP-адрес.
  • Table devices , which were columns Имя Хоста and IP-адрес.

In the main table in the columns of the host name and IP-address points ID-devices, which carried out a substitution of data from the device tables. In this paper, the structure of the first table and therefore the table will look different:

  • The main, which were columns Дата, Время, ID устройства.
  • Table devices , which were columns Имя Хоста and IP-адрес.

The Generating of the main table in the Application will be SQL-query and the table will be a column respectively Дата, Время, Имя Хоста and IP-адрес.

Qt

Aug. 15, 2015, 12:31 p.m.

QSqlRelationalTableModel, QSqlRelationalTableModel example, qt, qt таблицы, sql, sqlite

In Qt to represent table fields, which involve foreign keys to other tables database, QSqlRelationalTableModel can be used, which is a more advanced version QSqlTableModel class, which was considered in the previous article .

This class allows you to set relationships between tables and substitute values in the representation of the table formed by the values of the connected tables.

This article discusses the option of two tables. One table contains information about the devices (host name and IP address), and the second table ID of the device, which in the second table to be substituted host name and IP address of the device, respectively.

Project Structure for QSqlRelationalTableModel

Структура проекта

The project for this tutorial is a modified version of the preceding Article and remains unchanged.

Qt

Aug. 14, 2015, 1:44 p.m.

database, QSqlTableModel, QSqlTableModel example, qt, qt таблицы, sql, sqlite

In order to present the information in a database table we can to use the following classes:

  • QSqlQueryModel - model that generates a table by defining the raw SQL-query. It may be useful in the formation of a special custom filters and compile information from various database tables. About it in more detail in later lessons.
  • QSqlTableModel - the subject of our discussion in this article. The model that generates the table from database using name of table. But we can to create table without information from other tables.
  • QSqlRelationalTableModel - a class that allows you to create a table with constraints from other tables, substituting the values of the table, which is the model on contained in other tables record ID.

For comfortable work with information that is placed in the database applied additional class, which partially constitutes a "facade" design pattern.

Project structure for QSqlTableModel

he project is created as an application Qt Widgets, and it contains the following files:

  • DataBase.pro - project profile;
  • mainwindow.h - header file of mainwindow;
  • mainwindow.cpp - source file of mainwindow;
  • main.cpp - file with main function;
  • mainwindow.ui - interface of mainwindow;
  • database.h - header file of helper class to be used for information that is placed in a database;
  • database.cpp - source file of helper class to be used for information that is placed in a database;
Donate

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

A
March 29, 2020, 12:14 p.m.
Alexanderv66

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

  • Result:71points,
  • Rating points1
A
March 29, 2020, 12:05 p.m.
Alexanderv66

C ++ - Test 004. Pointers, Arrays and Loops

  • Result:80points,
  • Rating points4
DE
March 28, 2020, 3:13 p.m.
Denis Erokhin

C++ - Test 005. Structures and Classes

  • Result:100points,
  • Rating points10
Last comments
March 27, 2020, 2:40 p.m.
Evgenij Legotskoj

Добрый день. В конце пятой статьи скачать можете.
March 27, 2020, 2:28 p.m.
mkdir _

Здравствуйте, а можно, пожалуйста, ссылку на целые исходники, если есть?
March 27, 2020, 4:36 a.m.
Evgenij Legotskoj

Скорее всего также, как и для установки всех остальных переменых в CMake, через использование set
March 27, 2020, 2:47 a.m.
Andrej Jankovich

Ошибка с ярлыками в Windows исправлена в версиии 1.4.0.4
March 26, 2020, 1:37 p.m.
Andrej Jankovich

но появятся ярлыки, сейчас поправим
Now discuss on the forum
March 30, 2020, 4:16 a.m.
Evgenij Legotskoj

Попробуйте запустить через плейлист, а не через setMedia. Пример есть в этой статье
March 30, 2020, 3:25 a.m.
Evgenij Legotskoj

Добрый день. Почитайте документацию, в исходниках этой библиотеки есть исходнные классы логгеров. Вам наверняка достаточно только правильно вызвать пару функций, чтобы задать имя файла…
March 30, 2020, 3:17 a.m.
Evgenij Legotskoj

Нет, не нужно ничего умножать, если у вас включена поддержа High DPI в приложении а QML, то достаточно держать в памяти, что все значения задаются в DPI, и просто задаёте значения равные DPI сра…
March 27, 2020, 10 a.m.
Mihailll

Оказывается нужно сделать столбец уникальным ALTER TABLE public.drivers ADD UNIQUE (agregator1_id); Потом так работает INSERT INTO drivers( name_driver, surname, middle_name, agr…
s
March 27, 2020, 8:25 a.m.
shuric

Спасибо за ответы. Скорее всего оставлю на неопределенное время под macOS. Хоть будет полезно другим начинающим разработчикам.
EVILEG
About
Services
© EVILEG 2015-2019
Recommend hosting TIMEWEB