The am having trouble retrieving the text entered into a QLineEdit widget.
The window displays and allows entry.
When the return key is pressed the signal is generated and the slot executed. The code to assign the value of the text of the QLineEdit appears to work, but when the value is printed the data entered is not there and the database select shows the record which is on the database with the key entered was not found.
Here is the code and the output of the execution.
import os
import sys
import sqlite3
import PySide6
#QUiLoader allows screen created in QT Designer to be loaded
from PySide6.QtUiTools import QUiLoader
from PySide6.QtCore import QSize
from PySide6.QtSql import QSqlDatabase, QSqlQuery, QSqlQueryModel
from PySide6.QtWidgets import (
QApplication,
QComboBox,
QDataWidgetMapper,
QDoubleSpinBox,
QFormLayout,
QLabel,
QLineEdit,
QMainWindow,
QSpinBox,
QWidget,
)
sys_cust_code = ""
loader = QUiLoader()
basedir = os.path.dirname(__file__)
class ci_widget(QWidget):
def __init__(self):
super().__init__()
self.ui = loader.load(
os.path.join(basedir, "windows/cust_input.ui"), None
)
self.ui.setWindowTitle("Input Customer Code")
sys_cust_code = self.ui.ci_input.text()
self.ui.ci_input.returnPressed.connect(check_customer)
self.ui.show()
def check_customer():
print("Customer Code Entered")
print("Sys_cust_code = ", sys_cust_code)
db = QSqlDatabase("QSQLITE")
db.setDatabaseName(os.path.join(basedir, "databases/integrity.db"))
db.open()
connection_obj = sqlite3.connect('databases/integrity.db')
cursor_obj = connection_obj.cursor()
cursor_obj.execute('SELECT * FROM customer WHERE cust_code = ?', (sys_cust_code,))
customer_rec = cursor_obj.fetchone() # holds data from customer database
if customer_rec == None:
sys_cust_found = "N"
else:
sys_cust_found = "Y"
print("sys_cust_found = ",sys_cust_found)
print("sys_cust_code = ",sys_cust_code)
#quit()
app = QApplication(sys.argv)
ui = ci_widget()
app.exec()
Thanks in advance for your assistance.
Here is a screenshot of the output.