Aug. 19, 2015, 7:59 a.m.

Qt

mapper, QDataWidgetMapper, QDataWidgetMapper example, QSqlTableModel, qt, sql

To display the data in a widget with an arbitrary use QDataMapperWidget class. To work with this widget is still required model for presentation.

For example, QSqlTableModel or QSqlRelationalTableModel , but the data is not already substituted QTableView , and various arbitrary objects. For example QLineEdit or QComboBox . Or in the dialog box to add records with which to work in this article.

Thus, the problem is as follows. Write a program that displays a list of computers in the table, and each computer has three data fields: Имя Хоста, IP-адрес и MAC-адрес. There should also be a button to display the dialog box, through which we can add a new device to the table. Also, we should be able to edit the records through the same dialog box.

Project structure of QDataWidgetMapper

The project is created as an application Qt Widgets, where the following files are created:

  • QDataMapperWidget.pro ;
  • mainwindow.h - header file of the main application window;
  • mainwindow.cpp - source code of window;
  • main.cpp - the main source file from which the application starts;
  • mainwindow.ui - form of the main application window;
  • database.h - header file of helper class to be used for information that is placed in a database;
  • database.cpp - source code of helper class file to be used for information that is placed in a database;
  • dialogadddevice.h - header file dialog to add or edit entries;
  • dialogadddevice.cpp - source file dialog box to add and edit entries;
  • dialogadddevice.ui

Note. Most of the interface is created in the designer, so as not to clutter up the main logic code superfluous information. In fact it is only a matter of taste and habit.

Aug. 15, 2015, 4: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, 5: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;
s
May 26, 2019, 2:33 p.m.
simpleunderground

Qt - Test 001. Signals and slots

  • Result:31points,
  • Rating points-10
НД
May 25, 2019, 11:19 p.m.
Николай Демиденко

C++ - Test 002. Constants

  • Result:50points,
  • Rating points-4
Last comments
May 21, 2019, 8:10 p.m.
Дмитрий

Приветствую! Я думаю дойдёт и до этого, но пока изучать его у меня нет желания.
May 20, 2019, 7:20 p.m.
Евгений Легоцкой

Добрый день! Вы не думали разместить репозиторий проекта на GitHub?
P.
May 18, 2019, 2:03 p.m.
PELMYACH .

Спасибо большое! Вскоре буду разбираться!
May 18, 2019, 9:13 a.m.
Евгений Легоцкой

Добрый день! Отнимать значение общего счётчика можно в деструкторе класса кнопки QDynamicButton::~QDynamicButton(){ ResID--;} При этом я бы ещё переустанавливал значения вс...
P.
May 14, 2019, 10:33 p.m.
PELMYACH .

Здравствуйте!А не подскажите, как можно при удалении какой либо кнопки, у щётчика отнять значение?Дабы например четвёртой кнопке соответствовал ID 4, а не 5 скажем
Now discuss on the forum
May 26, 2019, 6:49 a.m.
Михаиллл

Скачал dll от сюда и заработало
May 24, 2019, 6:48 a.m.
Евгений Легоцкой

Если там будут только перечисления внутри namespace, то жа, достаточно будет заголовочного файла
May 24, 2019, 6:28 a.m.
Андрей Янкович

работает любой http сервер, и можно использовать обсалютно любой портпример <RemoteRepositories> <Repository> <Url>http://178.124.160.6:3030/A/B&l...;
May 23, 2019, 10:42 a.m.
Михаиллл

Спасибо, помогло.
May 23, 2019, 6:31 a.m.
Евгений Легоцкой

Для задач и граф-то не нужен. Достаточно будет таблицы в локальной базе данных SQLite, в которой указывается задача, время и т.д. В этом разделе есть примеры по работа с базой д...
25,000.00 руб. - 30,000.00 руб.
Разработчик Qt/C++
Barnaul, Altai Krai, Russia

For registered users on the site there is a minimum amount of advertising

EVILEG
About
Services
Join us
© EVILEG 2015-2019
Recommend hosting TIMEWEB