Я использую отдельный метод класса в другом потоке (создан threading.Thread
). Я хочу проверить, успешно ли пользователь вошел в систему или нет.
Если пользователь не вошел в систему, я хочу вывести сообщение:
QtWidgets.QMessageBox.critical(
None,
"Wrong Credentials",
"The login credentials provided in settings are wrong. Kindly edit them and restart the application"
)
Ошибка
QObject::setParent: Cannot set parent, new parent is in a different thread
QBackingStore::endPaint() called with active painter; did you forget to destroy it or call QPainter::end() on it?
Segmentation fault (core dumped)
Код
"""
include all related imports
"""
# Code for Ui_Dialog is not important
class Application(Ui_Dialog):
def __init__(self, Dialog):
self.completer = QtWidgets.QCompleter(["days", "weeks", "months"],
Dialog)
self.recent_profiles: List[Dict[str, Union[str, WebElement]]] = []
self.parent = Dialog
Dialog.setWindowFlags(QtCore.Qt.WindowCloseButtonHint
| QtCore.Qt.WindowMinimizeButtonHint)
qtRectangle = Dialog.frameGeometry()
centerPoint = QtWidgets.QDesktopWidget().availableGeometry().center()
qtRectangle.moveCenter(centerPoint)
Dialog.move(qtRectangle.topLeft())
self.setupUi(Dialog)
self.retranslateUi(Dialog)
self.db = self.__load_db()
Thread(
target=self.__run_auto,
args=(
self.db["auto"],
self.db["email"],
self.db["password"],
)
).start()
def __run_auto(self, auto, email, password):
if not auto["predicate"] or not auto["lim"] or not auto["template"]:
QtWidgets.QMessageBox.critical("Error", "Auto recent sender is not configured") # the problem occurs here
else:
options = Options()
options.headless = False
driver: WebDriver = WebDriver()
driver.get("https://example.com/user/login")
user: WebElement = driver.find_element_by_xpath('//*[@id="username"]')
pasw: WebElement = driver.find_element_by_xpath('//*[@id="password"]')
login: WebElement = driver.find_element_by_xpath(
'/html/body/div[1]/main/div/form/div[3]/button')
user.send_keys(email)
pasw.send_keys(password)
login.click()
SUCCESS = False
try:
WebDriverWait(driver, 2).until(
EC.presence_of_element_located(
(By.XPATH,
"/html/body/div[1]/main/div/form/div[2]/div/a")))
except (NoSuchElementException, TimeoutException):
SUCCESS = True
pass
if not SUCCESS:
# the problem occurs here
QtWidgets.QMessageBox.critical(
None,
"Wrong Credentials",
"The login credentials provided in settings are wrong. Kindly edit them and restart the application"
)
driver.quit()
pass
def __load_db(self):
with open("/home/jarvis/config.json") as file:
return json.loads(file.read())
Также я был бы благодарен, если бы вы могли рассказать мне, как передавать объекты родительского потока в дочерний поток.