Privacy policyContactsAbout siteOpinionsGitHubDonate
© EVILEG 2015-2018
Recommend hosting
Aug. 19, 2015, 7:59 a.m.


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:

  • ;
  • 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.


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.


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:

  • - 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;
March 25, 2019, 5:32 p.m.
Ilya The Engineer

Qt - Test 001. Signals and slots

  • Result:5points,
  • Rating points-10
March 25, 2019, 8:34 a.m.

C++ - Test 002. Constants

  • Result:41points,
  • Rating points-8
March 25, 2019, 8:25 a.m.

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

  • Result:66points,
  • Rating points-1
Last comments
March 26, 2019, 8:49 a.m.
Евгений Легоцкой

Да Да Да. Я тоже сейчас вспомнил, что проблема -R в том, что права и для файлов и для каталогов устанавливаются. А для веб-серверов нужно, чтобы права на каталоги были 755, а на файлы 64...
March 26, 2019, 8:47 a.m.
Ruslan Polupan

Был не прав....Почитал маны, флаг «выполнения» по-разному действует на файлы и каталоги.Правильно так chmod -R go=rX,u=rwX /path/to/target/dir
March 26, 2019, 8:35 a.m.
Евгений Легоцкой

По моему, только эта директория /path/to/target/dir и получит эти права, а все остальные вложенные остануться с тем, с чем были. UPD: Или я что-то жёстко путаю? ))) Надо переп...
March 26, 2019, 8:18 a.m.
Ruslan Polupan

А если так chmod -R 755 /path/to/target/dir
March 22, 2019, 12:32 p.m.
Евгений Легоцкой

Ну может бибилотеки не те положили? У вас сборка для MinGW, а либы для MSVC.
Now discuss on the forum
March 26, 2019, 12:07 p.m.
Евгений Легоцкой

Пожалуйста, не загружайте сейчас никакие изображения, это сейчас не работает. Вечером исправлю, остались ошибки на сервере после его переезда.
March 25, 2019, 12:43 p.m.

Как сделать чтоб при клике на ячейку(ос андроид) ее сразу можно было редактировать?QGuiApplication::inputMethod()->show(); показывает клавиатуру, а вот что до этого прописать чтоб текст в ...
March 24, 2019, 10:36 a.m.

Отвечу на свой же вопрос, может кому то это пригодится. Да, можно в функции main использовать такую конструкцию. При запуске программы из Qt передаю свой аргумент в параметрах командной строк...
March 22, 2019, 12:29 p.m.

Да, мьютекс добавил, но в том потоке, где сигнал вызывается.
Join us in social networks

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