Nov. 24, 2015, 8:11 a.m.


База данных, SQLite, Qt, QML, Android, DataBase, Model, View, MVC

A small example to work with the database in QML Qt. This lesson brings together information on the use of signals and slots in the Qt QML , access to C++ classes from QML layer implementation of the application interface on QML, as well as the implementation of the model/view for the database tables.

The database contains a table with a list of people, which has four columns:

  • id (INTEGER) - a unique record number;
  • FirstName (VARCHAR (255)) - First Name;
  • SurName (VARCHAR (255)) - Last Name;
  • Nik (VARCHAR (255)) - Nik name.

The application must implement removing and adding records to the database through the application interface. To add records to the database three fields for data entry will be used and a button that initiates the addition of data to an SQL database. Adding entries to the table through a wrapper class designed for this application is present in metodom.Takzhe ListModel class that implements the model of data representation for the information display in the TableView in QML layer.

Nov. 20, 2015, 9:23 a.m.


DECIMAL, INTEGER, MS SQL, Qt, SQL, типы данных

In the process of application development for Qt, which will have to work with databases, you must take into account the nuance that Qt driver target Databases may not support all types of data that you can lay in your database. For example, one such example, which faced one of the Readers site, this is the problem with data type mapping DECIMAL through QSqlTableModel . At that time, both in the development of applications in the C++ Builder, this type of data displayed in the fine.

And the work was done with the database MS SQL database for which an ODBC driver used. The results of the applications on C ++ Builder and Qt are shown in the following figures. The difference in the external tables, as is that in Qt applications are no values in the view, where the type of data in the database has been declared as DECIMAL .

Nov. 18, 2015, 9:14 a.m.


QSqlTableModel, Qt, paint

In the lesson on working with QSqlTableModel was detailed mapping table data from a SQL database. But with the question from one of the readers, do a small addition to this example.

The question was how to paint an entire row depending on the value in one of the columns. In the example of operation performed with the addition of QSqlTableModel data base rows with the date, time, and a pseudo-random number notification of the pseudo-random number. In this regard, the lines were selected as test lines, where the pseudo-random number is equal to 41.

To do this, you must inherit from QSqlTableModel class and override the method QSqlTableModel::data() . Then use as a data model, a new class of heir.

Nov. 11, 2015, 7:25 a.m.


QML, Qt, QDataWidgetMapper, mapper, QMLDataMapper

In the process of transferring a GUI softiny with QWidgets on QML QDataWidgetMapper found no analogue for QML. This fact was somewhat spoiling the mood. But there was nothing, but to look for other ways to implement or make their full version of this, your Qml Data Mapper.

Nevertheless, searching on the web expanses yielded the results as an example in 2011 by Nokia developers to implement the SQL Widget Mapper for BlackBerry based on Cascades (framework for native development on QML Qt under BlackBerry, respectively). By evening meditation on the present example was able to saw through the code for the current QML Qt, which is quite nice to feel like when working under the Desktop, and when running under Android, (cross-platform no matter how how).

To demonstrate the QML Data Mapper will write an application that works with the SQLite database. Each time an application writes a few lines in a database, from which data are collected using a data model to inherit from QSqlQueryModel and displayed in QML TableView. The main window of the application there is a button, pressing that cause, which displays information on the first row of the table dialog. When you double-click on one of the rows in a table is also called a dialog box, but the information on this line. Also present button in the dialog box to scroll through the information from the table.

Nov. 10, 2015, 7:06 a.m.


anchors, left, right, bottom, top, centerIn, Qt, QML

In addition to the more traditional Grid , Row , and Column , Qt Quick also provides a way to layout items using the concept of anchors . Each item can be thought of as having a set of 7 invisible "anchor lines":

  • left;
  • horizontalCenter;
  • right;
  • top;
  • verticalCenter;
  • baseline;
  • bottom.

The baseline (not pictured above) corresponds to the imaginary line on which text would sit. For items with no text it is the same as top .

Nov. 9, 2015, 3:03 a.m.


ListView, ListModel, TextInput, Model, Delegate, QML, Qt, Android, View

Working with the ListView in QML is a fairly common aspect in the development of Android applications, since many applications have in their functional building lists of data, records, settings, etc. It is also true in developing a Desktop applications with QML principle would be the same for both platforms.

For its consideration of the transfer of information in the list offer carefully consider the following scenario of interaction with the ListView .

The principle of view data in the ListView

ListView object has two important properties:

  1. delegate - which determines the appearance of a single element ListView
  2. model - which placed the data of each element

The transmission model can be used ListModel object that contains the data for each item in the list. The data assigned to variables that have been assigned to certain properties of the objects in the delegate. In the figure below has two delegate objects Text, text properties which the variables text_first and text_second assigned. These variables determine which will be substituted data from each ListElement in ListModel . As can be seen from the figure, each ListElement has two properties, the name of which is identical to the variables that are assigned to the delegate. In fact, these variables are roles, which put a value of ListModel . So we get ListView with text fields, which are filled with the data that have been made in each ListElement in ListModel .

Nov. 6, 2015, 7:17 a.m.


GridLayout, Qt, QML, ячейка, cell, row, column

A short note, born out of the question of one of the regular readers of the site. When developing the application interface under QML for positioning objects in the GridLayout is necessary to use the functionality of embedded properties Layout. Such as:

  • Layout.row - indicates the line where the object is located;
  • Layout.column - indicates the column in which the object is located;
  • Layout.rowSpan - indicates how many lines should be stretched object;
  • Layout.columnSpan - indicates how many columns should be stretched object;
  • Layout.minimumWidth - the minimum width of an object in a layer;
  • Layout.minimumHeight - the minimum height of the object in a layer;
  • Layout.preferredWidth - the preferred width of the object in a layer;
  • Layout.preferredHeight - the preferred height of the object in a layer;
  • Layout.maximumWidth - the maximum width of the object in a layer;
  • Layout.maximumHeight - the maximum height of an object in a layer;
  • Layout.fillWidth - filling in width;
  • Layout.fillHeight - filling height;
  • Layout.alignment - alignment layer;
Nov. 5, 2015, 2:26 a.m.


QML, SQL, Qt, DataBase, QSqlQueryModel, TableView

To represent database tables in the development TableView using QML You can use a class inherited from QSqlQueryModel . To do this, in the inherited class to define a method that would establish the respective roles of the table columns to the corresponding columns in the TableView, defined in the QML , which also indicates the roles of each object TableViewColumn , that is, for each column. You will also need to override a method QVariant data(...) const , which returns the data for the table cells. In this case, the information will be returned in accordance with certain roles columns of the table.

The project structure to work with TableView

The project consists of the following files:

  • - the profile of the project;
  • database.h - header to create and initialize the test database;
  • database.cpp - file source code to create and initialize the test database;
  • model.h - header data model file;
  • model.cpp - file source data model;
  • main.cpp - the main source file;
  • main.qml - qml file TableView.
Nov. 2, 2015, 1:55 a.m.


Qt, QML, reference error, TabView

The structure of objects in Qml is a tree in which to access the properties of objects underlying level please refer to the original object, then select the child object and select the child object property to which you want to access.

But in the case TabView this approach does not work, because the objects tabs added dynamically, so you need to access the tab on its index, pick up an object from the item and find it of interest to us a child object in this item also on the index. And then get access to the property of interest to us. It is also recommended to note that in this case, the code does not work completion QtCreator .

And most likely you will get an error as follows:

ReferenceError: 'something' is not defined

Nov. 1, 2015, 11:39 a.m.


QSystemTrayIcon, Qt, QML

When moving the application interface from Qt / C ++ to Qt / QML my hands reached and application icons in the system tray. The aim was to put an icon in the System Tray from C ++ to QML, partially or completely. The first option, which I realized, was a wrapper around QSystemTrayIcon with QMenu using a system of signals and slots . The solution is quite logical, given that in QML is not a facility, like MenuBar to System Tray. So we do a wrapper, which can interact in QML layer.

After the wrapper was implemented, I had the opportunity to consult with the programmer of Wargamming  - Constantine Lyashkevich , who recommended me to pay attention to what QML can have access not only to the signals and slots, and the parameters of the Q_PROPERTY , who also were in the class QSystemTrayIcon , that is, in fact it was only possible to register this class as the type layer in QML and try to write almost all the code on the QML. I checked the board and talked about by Constantine. As a result, he became interested in this problem and we spent the evening entertaining hour of attempts and jointly stuffed QSystemTrayIcon maximum in QML.

So in this article you will see two implementations to work with an icon in the system tray.

The resulting application will minimize to the System Tray by clicking the icon in the system tray, as well as by pressing the close button. But only in the event that will be active the special checkbox to control the folding process of the application window to the system tray, if the checkbox is not enabled, the application will be closed. Also, the application can be closed with an active checkbox menu item in the system tray icon.


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

Feb. 25, 2020, 4:40 a.m.

C++ - Test 005. Structures and Classes

  • Result:83points,
  • Rating points4
Feb. 24, 2020, 1:47 p.m.
Dmitrij Zlobin

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

  • Result:40points,
  • Rating points-8
Feb. 17, 2020, 1:41 p.m.

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

  • Result:85points,
  • Rating points6
Last comments
Feb. 24, 2020, 2:54 a.m.
Evgenij Legotskoj

Добрый день. Там будет url, на который указывает ссылка тега a в пагинаторе, если правильно помню )) Написал этот код и забыл.
Feb. 23, 2020, 11:37 p.m.

Евгений Здравствуйте! Не могу понять вот эту часть кода: url: jQuery(this).attr('action') наверное здесь должен быть путь к url, тогда 'action' на какой url указывает?
Feb. 17, 2020, 2:22 a.m.
Evgenij Legotskoj

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

Добрый вечер! Монжно по подробней о теге get_companion? ссылка не работает.
Now discuss on the forum
Feb. 25, 2020, 7:06 a.m.

Feb. 24, 2020, 11:04 a.m.
Evgenij Legotskoj

Добрый день. Вот пример с дружественного ресурса с движением камеры
Feb. 24, 2020, 5:29 a.m.
Evgenij Legotskoj

Qt не предоставляет функционала по запросу root прав во время выполнения программы. Поэтому нужно использовать платформозависимый функционал, для Linux это будет выглядеть так: #include…
Feb. 24, 2020, 2:47 a.m.
Evgenij Legotskoj

Добрый день. Что означает клиентская область? Это изображение? Вам нужно распознавать символы текста или всё-таки пользователь будет вводить текст с клавиатуры, просто в любом месте "абстр…
Feb. 21, 2020, 4:19 a.m.
Vladimir Zhitkovsky

void sendImage(int sessid, int type, int dest, int format, QString imgBase64Data){ QNetworkRequest request; request.setUrl(QUrl(ipAddress + "ctlapi/cmd=preparereportimg&sessid=…
© EVILEG 2015-2019
Recommend hosting TIMEWEB