PDA

View Full Version : More SQLite Woes and onFocus Woes



morraine
13th August 2008, 11:41
AS if the problem i had yesterday is not enough i have another problem this time its just selecting a simple record from the database. i have this code:



class loginPageView(QWidget, ui_loginui.Ui_Mainlogin):

def __init__(self, parent=None):
super(loginPageView, self).__init__(parent)
self.setupUi(self)
self.lineEditer_login.setFocus()
self.connect(self.lineEditer_login, SIGNAL("returnPressed()"), self.sqlEnterlogin)


def sqlEnterlogin(self):
texer = self.lineEditer_login.text()
query = QSqlQuery()
query.exec_("SELECT staff_id FROM staff WHERE password = pass1") ### %s" % (texer))
if query.next():
self.lineEditer_login.clear()
texer2 = unicode(query.value(STAFF_ID).toString())
self.lineEditer_login.setText("hello are you working? %s" % (texer2))
##self.emit(SIGNAL("loginSuccessful"))
else:
texer3 = QSqlQuery().lastError().text()
self.lineEditer_login.setText("why are you not working? %s" % (texer3))
QApplication.processEvents()


first is the self.lineEditer_login.setFocus() which is conflicting with a QGraphicsView Box on the ui_loginui.py layout page because if i comment out the code for the QGraphicsView Box then the QLineedit box gets focus as soon as the page is executed.

and the second problem is the SQL select wont work for some unexplained weird reason

I've attached all files if some one with some python experience can have a look at please. the script will create and sql lite database and then insert some data into it but it just wont select from it i don't even get an error message as I've tried to set up above to display what the problem is.

Your help on this will be very appreciated, Thanks

morraine
13th August 2008, 14:14
thats sorted it

ive sorted the SQlite problem out just needed to put single quotes around the query value and i needed to continue the sql object on to the error object and not try to create a totally new object.
(still getting to grips with object oriented programing)

Ive been following this book learning about PYQT, but Ive been following it to strictly because some of it has been done with out the proper syntax which has me thrown as im like well ive done what's in the book why ain't it working!?!?!? Any ways thanks



def sqlEnterlogin(self):
texer = self.lineEditer_login.text()
query = QSqlQuery()
query.exec_(unicode(QString("SELECT staff_id FROM staff WHERE password = '%1'").arg(texer))) ### %s" % (texer))
if query.next():
self.lineEditer_login.clear()
texer2 = unicode(query.value(0).toString())
self.lineEditer_login.setText("hello are you working? %s" % (texer2))
##self.emit(SIGNAL("loginSuccessful"))
else:
texer3 = query.lastError().text()
self.lineEditer_login.setText("hello are you working22? %s" % (texer3))
QApplication.processEvents()

but if any one has any solutions for why the QgraphicsView box is conflicting with the QLineEdit box then i would love to know about it
thanks