Z
Z
ZIK13372021-01-18 13:43:54
Python
ZIK1337, 2021-01-18 13:43:54

What causes the CreateFontIndirect failed for family error?

PyQt application, with a QTableWidget table, QTextBrowser and other forms (I just don't know what specifically caused the error).
There is a list of several thousand elements, each element is checked and a row is added to the table.
Actually, if you check 1000 at a time, then everything works fine.
I also tried 2000, 3000, 4000, but errors have already appeared on 5000:

QWindowsFontDatabase::createEngine: CreateFontIndirect failed (Операция успешно завершена.)
QWindowsFontEngine::QWindowsFontEngine: CreateFontIndirect failed for family 'MS Shell Dlg 2' (Операция успешно завершена.)
QWindowsFontEngine::QWindowsFontEngine: GetTextMetrics failed (Неверный дескриптор.)
QWindowsFontDatabase::createEngine: CreateFontIndirect failed (Операция успешно завершена.)
QWindowsFontEngine::QWindowsFontEngine: CreateFontIndirect failed for family 'MS Shell Dlg 2' (Операция успешно завершена.)
QWindowsFontEngine::QWindowsFontEngine: GetTextMetrics failed (Неверный дескриптор.)
QWindowsFontDatabase::createEngine: CreateFontIndirect failed (Операция успешно завершена.)
QWindowsFontEngine::QWindowsFontEngine: CreateFontIndirect failed for family 'Arial' (Операция успешно завершена.)
QWindowsFontEngine::QWindowsFontEngine: GetTextMetrics failed (Неверный дескриптор.)
QWindowsFontDatabase::createEngine: CreateFontIndirect failed (Операция успешно завершена.)
QWindowsFontEngine::QWindowsFontEngine: CreateFontIndirect failed for family 'MS UI Gothic' (Операция успешно завершена.)
QWindowsFontEngine::QWindowsFontEngine: GetTextMetrics failed (Неверный дескриптор.)
QWindowsFontDatabase::createEngine: CreateFontIndirect failed (Операция успешно завершена.)
QWindowsFontEngine::QWindowsFontEngine: CreateFontIndirect failed for family 'SimSun' (Операция успешно завершена.)
QWindowsFontEngine::QWindowsFontEngine: GetTextMetrics failed (Неверный дескриптор.)
QWindowsFontDatabase::createEngine: CreateFontIndirect failed (Операция успешно завершена.)
QWindowsFontEngine::QWindowsFontEngine: CreateFontIndirect failed for family 'Arial Unicode MS' (Операция успешно завершена.)
QWindowsFontEngine::QWindowsFontEngine: GetTextMetrics failed (Неверный дескриптор.)
QWindowsFontDatabase::createEngine: CreateFontIndirect failed (Операция успешно завершена.)
QWindowsFontEngine::QWindowsFontEngine: CreateFontIndirect failed for family 'Segoe UI Emoji' (Операция успешно завершена.)
QWindowsFontEngine::QWindowsFontEngine: GetTextMetrics failed (Неверный дескриптор.)
QWindowsFontDatabase::createEngine: CreateFontIndirect failed (Операция успешно завершена.)
QWindowsFontEngine::QWindowsFontEngine: CreateFontIndirect failed for family 'Segoe UI Symbol' (Операция успешно завершена.)
QWindowsFontEngine::QWindowsFontEngine: GetTextMetrics failed (Неверный дескриптор.)

There are a lot of them, I do not see the point in adding them all.
Like some resources are missing or what? What is the reason and how can I fix it?

Table settings:
spoiler
AIAono9.jpg
BvFao2e.jpg
iXHRsD3.jpg

The QTextBrowser settings (there is a list in it) just in case, although it is no longer changed when checked:
spoiler
zeWxj50.jpg
LHiA4BQ.jpg
Bfcglhw.jpg

PS
Now I saw 1 more small output to the console, but the program did not crash. This is when I scrolled in the table when the last elements were added to it (or the last one is straight):
spoiler
OpenType support missing for "Segoe UI", script 20
  OpenType support missing for "MS Shell Dlg 2", script 20
  OpenType support missing for "Arial", script 20
  OpenType support missing for "MS UI Gothic", script 20
  OpenType support missing for "SimSun", script 20
  OpenType support missing for "Arial Unicode MS", script 20
  OpenType support missing for "Segoe UI Emoji", script 20
  OpenType support missing for "Segoe UI Symbol", script 20
  OpenType support missing for "Nirmala UI", script 20

PPS
Now I tried to wrap in try except adding a row to the table - it did not help, then the error is not in the table.

PPPS
It seems like I localized the function where the error occurs - when deleting duplicates from the list (or rather, duplicate accounts by login). But the wrapper in try except didn't help either...
Code ready to run
import sys
from PyQt5 import QtWidgets, QtGui, QtCore, Qt
from time import sleep
import threading


class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(1479, 781)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(MainWindow.sizePolicy().hasHeightForWidth())
        MainWindow.setSizePolicy(sizePolicy)
        MainWindow.setMinimumSize(QtCore.QSize(1479, 781))
        MainWindow.setMaximumSize(QtCore.QSize(1479, 781))
        font = QtGui.QFont()
        font.setPointSize(9)
        MainWindow.setFont(font)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.centralwidget.sizePolicy().hasHeightForWidth())
        self.centralwidget.setSizePolicy(sizePolicy)
        self.centralwidget.setMinimumSize(QtCore.QSize(1479, 781))
        self.centralwidget.setMaximumSize(QtCore.QSize(1479, 781))
        self.centralwidget.setObjectName("centralwidget")
        self.label = QtWidgets.QLabel(self.centralwidget)
        self.label.setGeometry(QtCore.QRect(0, 0, 61, 16))
        self.label.setObjectName("label")
        self.all_accounts = QtWidgets.QTextBrowser(self.centralwidget)
        self.all_accounts.setGeometry(QtCore.QRect(0, 20, 791, 521))
        self.all_accounts.setLineWrapMode(QtWidgets.QTextEdit.NoWrap)
        self.all_accounts.setReadOnly(False)
        self.all_accounts.setAcceptRichText(False)
        self.all_accounts.setObjectName("all_accounts")
        self.del_duplicate_accs = QtWidgets.QPushButton(self.centralwidget)
        self.del_duplicate_accs.setGeometry(QtCore.QRect(660, 550, 131, 23))
        font = QtGui.QFont()
        font.setPointSize(8)
        self.del_duplicate_accs.setFont(font)
        self.del_duplicate_accs.setObjectName("del_duplicate_accs")
        self.count_accs = QtWidgets.QLabel(self.centralwidget)
        self.count_accs.setGeometry(QtCore.QRect(430, 0, 91, 16))
        font = QtGui.QFont()
        font.setPointSize(9)
        font.setBold(True)
        font.setWeight(75)
        self.count_accs.setFont(font)
        self.count_accs.setObjectName("count_accs")
        self.retranslateUi(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "Check"))
        self.label.setText(_translate("MainWindow", "Аккаунты:"))
        self.del_duplicate_accs.setText(_translate("MainWindow", "Удалить дубли по лог."))
        self.count_accs.setText(_translate("MainWindow", "0"))


class ExampleApp(QtWidgets.QMainWindow, Ui_MainWindow):
    def __init__(self):
        super().__init__()
        self.setupUi(self)
        self.logins = []
        self.accounts = []
        self.max_threads = 200
        self.dupl_log = []
        self.thr = 0

        self.all_accounts.textChanged.connect(self.all_accounts_f)
        self.del_duplicate_accs.clicked.connect(self.del_dupl_accs)

    # изменение списка
    def all_accounts_f(self):
        self.accounts = []
        lists = self.all_accounts.toPlainText().split('\n')
        for l in lists:
            if l != '' and l != '\n':
                self.accounts.append(l)
        self.count_accs.setText(str(len(self.accounts)))

    # удалить дубликаты акков по логину
    def del_dupl_accs(self):
        self.all_accounts.blockSignals(True)
        if self.count_accs.text() != '0':
            self.all_accounts.clear()
            self.dupl_log = []
            self.logins = [item.split(':')[0] for item in self.accounts]
            self.logins = list(set(self.logins))
            for item in self.accounts:
                while self.thr > self.max_threads:
                    sleep(0.1)
                self.thr += 1
                x = threading.Thread(target=self.check_dupl, args=(item,), daemon=True)
                x.start()
            while self.thr > 0:
                sleep(0.1)
            for item in self.dupl_log:
                self.accounts.pop(self.accounts.index(item))

            self.count_accs.setText(str(len(self.accounts)))
        self.all_accounts.blockSignals(False)

    # поток для проверки дублей (по бд) по логину
    def check_dupl(self, item):
        if item.split(':')[0] in self.logins:
            self.logins.pop(self.logins.index(item.split(':')[0]))
            self.all_accounts.append(item)
        else:
            self.dupl_log.append(item)
        self.thr -= 1


def main():
    app = QtWidgets.QApplication(sys.argv)
    window = ExampleApp()
    window.show()
    app.exec_()


if __name__ == '__main__':
    main()

List on which you can check: https://pastebin.com/KAUq6nM6

The essence in short:
List - a list of accounts in the format login:password:token or login:password.
Doubles by login are removed from this list (with the first unique one remaining), and if necessary, this login is also compared in the database to see if it is there. If there is, it is also removed from the list.
all_accounts is QTextBrowser
accounts - list
And now if you insert 5000 or more lines (well, press the button) - errors fly

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andy_U, 2021-01-18
@Andy_U

First, deal with the kryakozyabrs - this is the wrong encoding. 866 instead of 1251 or vice versa.
What is script 20 - see: https://docs.microsoft.com/en-us/typography/openty...
You are doing something strange with fonts. Although this may be the result of the fact that the memory is over / broken. Just in the console version, working with the database does not cause errors?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question