Advanced search

Qt

Aug. 19, 2015, 3: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:

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

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