Privacy policyContactsAbout siteOpinionsGitHubDonate
© EVILEG 2015-2018
Recommend hosting
TIMEWEB
Oct. 26, 2018, 9:35 p.m.

Qt

Qt5, QJsonArray, QJsonObject, QJsonDocument, JSON, Qt

Consider a small example of the formation of a JSON document from, for example, the text and the title of this text.

For example, the text has:

  • Title - First Title
  • Content - First Content

And so on

We will add this text to QJsonObject, which we will add to the QJsonArray text array. The array of objects will be in the general working QJsonObject, which we will save to a file.

We will do all this through a graphical interface in which we have:

  • QLineEdit - titleLineEdit - contains the title of the text to add
  • QTextEdit - contentTextEdit - contains the contents of the text to add
  • QTextEdit - jsonDocumentTextEdit - JSON document preview
  • QPushButton - addButton - button to add new text in JSON
  • QPushButton - clearButton - button to remove all texts from the current QJsonObject
  • QPushButton - saveButton - button to save JSON document to file
  • QPushButton - loadButton - button to read JSON from file

In this case, we will be able to read the JSON file and add additional texts to the read file.

The application will look like this.

Oct. 25, 2018, 6:47 a.m.

Django

django, сообщение, Python, чат

Gave free time to correct private messages on the site. This functionality is not used very often, so I do not make great efforts to improve it, although it is time to bring this functionality to adequate work.

Previously, there was a very big flaw, which was that the dialogue counter with unread messages was not shown, which led to the fact that the users who were sent the message simply did not pay attention to it, because they did not know about it.

Now I finally fixed this flaw. And in the framework of the previous code I will show which corrections were added.

Oct. 24, 2018, 6:38 a.m.

Django

BeaftifulSoup4, Django, Python, HTML, Python 3

When developing a web site that adds the ability to write comments or publish articles that allow html layout, the mechanism for clearing unwanted html tags, in particular script and style tags, is important, since malicious scripts on a quality resource definitely should not be present. It will also be good to be able to clean up the style of the text, especially if the resource implies a uniform style. The discordance of screaming fonts is not needed by anyone, and adds problems with the layout.

To implement this mechanism, I use the Python package Beautiful Soup 4 and finally wrote one class, which essentially does everything I need. Removes unnecessary tags, adds necessary classes to tags, saves classes in tags, if you need to leave them during stripping, this is important for classes that are added at the stage of writing a comment, for example, when inserting a YouTube video or adding program code when the user selects which programming language should be represented in the program code block.

Oct. 23, 2018, 10:11 a.m.

C++

cpp, C++17, fallthrough

Start at work to use a compiler that supports the standard C++17.

Actively we begin to use various features from this standard..

I was pleased with the [[fallthrough]] attribute for switch case constructions.

Oct. 11, 2018, 6:04 p.m.

Qt

Qt, QScriptEngine, QScriptValue, JavaScript, QScriptContext

Suppose you are faced with the task of executing JavaScript code in a C++ application. For example, there is a set of output data or variables whose names are known in advance, and there are pieces of JavaScript code that does something with these variables. And there is also an algorithm that, if there are any conditions, it will choose. which javascript code should be run.

Also, you can't just take and rewrite that JavaScript code into C++ code and hardcorely add it to the application. Since there are a lot of such pieces of code, at the same time other people are engaged in their maintenance and constantly add new pieces of code.

That is, in this case, the set of input data and JavaScript code for us is data, in some way the content that we launch using a certain algorithm, according to which we choose, under what conditions to choose one or another for the same set of input variables a piece of javascript code.

I hope that I clearly explained why we need to run the execution of JavaScript code in a C++ application.

I suggest to write an application that has two input fields for variable names, two input fields with input for the values of these variables in double format, in case of entering a value other than double data type, we will set the value to Undefined .

We will also add an TextEdit input field for writing JavaScript code that we will execute in our application.

And the last input field will be called Result (this will be TextEdit ), which will be responsible for the output of the new calculated values of the variables we entered.

Also add a QPushButton, which will run the execution of JavaScript code.

The application will look like the image below.

Oct. 10, 2018, 1:32 p.m.

C++

C++, once, pragma

Work on a large project allows in some cases to test some theories concerning a programming language.

It was always interesting if the build is really accelerated by using the #pragma once directive instead of the classic #ifndef #define #endif .

Check this acceleration on a small project is quite problematic, because if the project is going on average for 20 seconds, then we will most likely not see a tangible acceleration, because the assembly time will always float from 17 to 23 seconds.

But I had free time and managed to test this theory on a large project.

Oct. 9, 2018, 7:16 p.m.

Qt

Qt, DLL, dll, Windows, dynamic

The forum raised the question of how to create a dynamic library and correctly connect it to a third-party project. Periodically, such questions arise, so consider one option of creating a dynamic dll for Windows using the standard wizards in Qt Creator.

In this case, the option will not be considered when the project is divided into subprojects, which are compiled as libraries and then connected to the main project. Because it will be the dynamic internal libraries of the project. Let's create exactly the external library, which theoretically could be distributed in the form of binaries.

Create two projects:

  1. QuiLib - this will be an external dynamic library that will contain one dialog box. This dialog box will open in the main project.
  2. WithDynamicLibrary - the project that will be used to connect this dynamic library.

Oct. 1, 2018, 8:34 a.m.

Design Patterns

шаблоны проектирования, приспособленец, flyweight

Цели


  • Использование общего доступа для эффективного использования большого количества объектов.
  • Стратегия GUI Motif по замене тяжеловесных виджетов легкими виджетами.

Проблематика

Проектирование объектов вплоть до самых низких уровней «гранулярности» системы обеспечивает оптимальную гибкость, но может быть неприемлемо дорогим с точки зрения производительности и использования памяти.

Sept. 27, 2018, 9:11 a.m.

Design Patterns

шаблоны проектирования

Цели

  • Предоставить унифицированный интерфейс для набора интерфейсов в подсистеме. Фасад определяет интерфейс более высокого уровня, который упрощает использование подсистемы.
  • Обернуть сложную подсистему более простым интерфейсом.

Проблематика

Для сегмента клиентского доступа требуется упрощенный интерфейс для доступа к общей функциональности сложной подсистемы.

Sept. 26, 2018, 11:55 a.m.

Python 3

python, pool, пул, шаблоны проектирования

Example of the design pattern An object pool in the Python programming language.

A
Jan. 22, 2019, 9:22 p.m.
Allyonz

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

  • Result:40points,
  • Rating points-8
A
Jan. 22, 2019, 2:15 p.m.
Alex

Qt - Test 001. Signals and slots

  • Result:89points,
  • Rating points6
IO
Jan. 20, 2019, 6:39 p.m.
Ivan Otreshko

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

  • Result:0points,
  • Rating points-10
Last comments
Jan. 22, 2019, 1:17 p.m.
Евгений Легоцкой

Создайте тогда тему здесь на форуме в разделе Qt с выкладками кода и вашими попытками внедрения делегата, позже гляну или может кто-то ещё глянет из опытных пользователей.
I
Jan. 22, 2019, 1:13 p.m.
IscanderChe

Не проще тогда использовать сразу кастомный делегат с чекбоксом? Я попробовал, но там засада в том, что чекбокс показывается только при щелчке на ячейку, а дефолтно показывается значение. Как ...
Jan. 22, 2019, 12:15 p.m.
Евгений Легоцкой

Если будет не приемлемо потом, то тогда через кастомный Item Delegate нужно будет перерисовать ячейки в той колонке.
I
Jan. 22, 2019, 12:09 p.m.
IscanderChe

Получилось приемлемо. Спасибо!Нюанс только в том, что поле рядом с чекбоксом не пропадает, оно просто пустое, что видно при выделении ячейки. Но этого достаточно.
Jan. 22, 2019, 11:50 a.m.
Евгений Легоцкой

Переопределить метод data для той колонки и роли Qt::DisplayRole, чтобы в том случае возвращался QVariant() я так думаю... Но возможно, что у вас там будут нюансы, если вы туда чекбокс за...
Now discuss on the forum
Jan. 23, 2019, 7:54 a.m.
Михаиллл

Зарание спасибо.А еще на эту тему можно будет сделать статью. Это контент будет уникальным.
Jan. 23, 2019, 7:37 a.m.
Евгений Легоцкой

Hello. Maybe the English will be better for you? I think russian is not native language for you, or did I mistake? Did I undesrtood rightly, that you mean this documentation ( ...
I
Jan. 22, 2019, 1:45 p.m.
IscanderChe

Всем добрый день. Суть задачи: надо, чтобы в одной из колонок QTableView вместо хранимого в QSqlTableModel значения выводился чекбокс и при смене состояния чекбокса значения в базе тоже ...
M
Jan. 22, 2019, 1:15 p.m.
Max-P85

Евгений, огромное спасибо, все работает!
Join us in social networks

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