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

Qt

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-адрес.

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

Qt

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.

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

Qt

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

p
Feb. 17, 2020, 2:41 p.m.
pstMem

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

  • Result:85points,
  • Rating points6
z
Feb. 17, 2020, 6:02 a.m.
zet

C++ - Test 006. Enumerations

  • Result:80points,
  • Rating points4
z
Feb. 17, 2020, 5:49 a.m.
zet

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

  • Result:80points,
  • Rating points4
Last comments
Feb. 17, 2020, 3:22 a.m.
Evgenij Legotskoj

Добрый день. Это кастомный тег, помещается в файл, который находится в каталоге templatetags myapp/ templatetags/ myapp.py
B
Feb. 16, 2020, 1:36 p.m.
BahaMeirman

Добрый вечер! Монжно по подробней о теге get_companion? ссылка не работает.
Feb. 16, 2020, 9:35 a.m.
Evgenij Legotskoj

Добрый день. На GitHub исходники, можете посмотреть в официальном репозитории
B
Feb. 16, 2020, 9:29 a.m.
BahaMeirman

Здравстсвуйте Евгений, непонятно мне где эти исходники найти?
Now discuss on the forum
Feb. 19, 2020, 8:55 a.m.
Mihailll

Можно через сервер сделать
V
Feb. 19, 2020, 7:09 a.m.
Vitali

Да, прямо сходу не заработало, а сейчас просто некогда разбираться, да и я уже решил не использовать в этом приложении WebEngine. Ошибка: WebEngineContext used before QtWebEngine::initialize(…
Feb. 19, 2020, 7:01 a.m.
BlinCT

Просто реально не вижу тут каких то проблем в модели, вот вообще ничего. Но она все равно не отображается, то есть ладно бы если данные бы не появлялись а сама таблица была бы. Так и таблиц…
Feb. 19, 2020, 6:54 a.m.
Mihailll

понятно, думал что дебаг будет стандартно работать. спасибо за помощь!
EVILEG
About
Services
© EVILEG 2015-2019
Recommend hosting TIMEWEB