Bad-Coder
@Bad-Coder
(null)

Как решить TypeError: unsupported operand type(s) for &: 'QLineEdit' and 'int'?

compiler.py
# Interface.
from PyQt5 import uic
from PyQt5.QtWidgets import QApplication

# Threads.
from threading import Thread

# Run commands.
from os import system

# UI Setuping.
Form, Window = uic.loadUiType('compiler\\compilerWindow.ui')
app = QApplication([])
window = Window()
form = Form()
form.setupUi(window)
window.show()

# Compile class.
class Compiler:
    # Run compilation.
    def run(self):
        """Run compilation."""
        def executor():
            flags = form.flags.text()
            script = form.script.text()

            system(f'pyinstaller {flags} {script} && pause')

        compilation = Thread(target=executor)
        compilation.start()

    # Connect compile button.
    def connect(self):
        """Connect button."""
        form.compile.clicked.connect(self.run)

# Init compiler.
compiler = Compiler()

# Connect button.
compiler.connect()

# Running app.
app.exec_()


compilerWindow.ui
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>compilerWindow</class>
 <widget class="QMainWindow" name="compilerWindow">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>245</width>
    <height>100</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>CQC-Compiler.</string>
  </property>
  <widget class="QWidget" name="centralwidget">
   <widget class="QLabel" name="flagsText">
    <property name="geometry">
     <rect>
      <x>0</x>
      <y>0</y>
      <width>70</width>
      <height>20</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <family>Consolas</family>
      <pointsize>14</pointsize>
     </font>
    </property>
    <property name="text">
     <string>Flags:</string>
    </property>
   </widget>
   <widget class="QLineEdit" name="flags">
    <property name="geometry">
     <rect>
      <x>70</x>
      <y>0</y>
      <width>160</width>
      <height>20</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <family>Consolas</family>
      <pointsize>8</pointsize>
     </font>
    </property>
    <property name="styleSheet">
     <string notr="true">background-color: black;
color: white;
</string>
    </property>
   </widget>
   <widget class="QLabel" name="scriptText">
    <property name="geometry">
     <rect>
      <x>0</x>
      <y>30</y>
      <width>70</width>
      <height>20</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <family>Consolas</family>
      <pointsize>14</pointsize>
     </font>
    </property>
    <property name="text">
     <string>Script:</string>
    </property>
   </widget>
   <widget class="QLineEdit" name="script">
    <property name="geometry">
     <rect>
      <x>80</x>
      <y>30</y>
      <width>160</width>
      <height>20</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <family>Consolas</family>
      <pointsize>8</pointsize>
     </font>
    </property>
    <property name="styleSheet">
     <string notr="true">background-color: black;
color: white;
</string>
    </property>
   </widget>
   <widget class="QPushButton" name="compile">
    <property name="geometry">
     <rect>
      <x>100</x>
      <y>60</y>
      <width>91</width>
      <height>31</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <family>Consolas</family>
      <pointsize>12</pointsize>
     </font>
    </property>
    <property name="text">
     <string>Compile.</string>
    </property>
   </widget>
  </widget>
 </widget>
 <resources/>
 <connections/>
</ui>


При запуске возникает такая ошибка.
Traceback (most recent call last):
  File "c:\Users\IonE\OneDrive\Рабочий стол\ConsoleQuestEngine\compiler\compiler.py", line 12, in <module>
    Form, Window = uic.loadUiType('compiler\\compilerWindow.ui')
  File "D:\Python\lib\site-packages\PyQt5\uic\__init__.py", line 200, in loadUiType       
    winfo = compiler.UICompiler().compileUi(uifile, code_string, from_imports,
  File "D:\Python\lib\site-packages\PyQt5\uic\Compiler\compiler.py", line 111, in compileUi
    w = self.parse(input_stream, resource_suffix)
  File "D:\Python\lib\site-packages\PyQt5\uic\uiparser.py", line 1037, in parse
    actor(elem)
  File "D:\Python\lib\site-packages\PyQt5\uic\uiparser.py", line 828, in createUserInterface
    self.traverseWidgetTree(elem)
  File "D:\Python\lib\site-packages\PyQt5\uic\uiparser.py", line 806, in traverseWidgetTree
    handler(self, child)
  File "D:\Python\lib\site-packages\PyQt5\uic\uiparser.py", line 369, in createWidget     
    topwidget.setCentralWidget(widget)
  File "D:\Python\lib\site-packages\PyQt5\uic\Compiler\qtproxies.py", line 126, in __call__
    if self.flags & AS_ARGUMENT:
TypeError: unsupported operand type(s) for &: 'QLineEdit' and 'int'


Что делать, никогда такой ошибки не возникало.
  • Вопрос задан
  • 21 просмотр
Решения вопроса 1
sergey-gornostaev
@sergey-gornostaev Куратор тега PyQt
Седой и строгий
  1. Не обращаться к компонентам графического интерфейса из потоков. Qt - не является потокобезопасной.
  2. Переименовать поле flags во что-нибудь другое.
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы