Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

textChanged event not triggering in Pyqt4

How come the textChanged event is not happening whenever I input some data in the QLineEdit?

from PyQt4.Qt import Qt, QObject,QLineEdit
from PyQt4.QtCore import pyqtSlot,SIGNAL,SLOT
from PyQt4 import QtGui, QtCore

import sys


class DirLineEdit(QLineEdit, QtCore.QObject):
"""docstring for DirLineEdit"""

@pyqtSlot(QtCore.QString)
def textChanged(self, string):
        QtGui.QMessageBox.information(self,"Hello!","Current String is:\n"+string)  

def __init__(self):
    super(DirLineEdit, self).__init__()

    self.connect(self,SIGNAL("textChanged(QString&)"),
                self,SLOT("textChanged(QString *)"))


app = QtGui.QApplication(sys.argv)
smObj = DirLineEdit()

smObj.show()

app.exec_()

everything seems to be correct to me, what am I missing ?

like image 532
Ciasto piekarz Avatar asked Feb 14 '23 19:02

Ciasto piekarz


1 Answers

Replace following line:

self.connect(self,SIGNAL("textChanged(QString&)"),
            self,SLOT("textChanged(QString *)"))

with:

self.connect(self,SIGNAL("textChanged(QString)"),
            self,SLOT("textChanged(QString)"))

Or you can use self.textChanged.connect (handler should be renamed because the name conflicts):

class DirLineEdit(QLineEdit, QtCore.QObject):

    def on_text_changed(self, string):
            QtGui.QMessageBox.information(self,"Hello!","Current String is:\n"+string)  

    def __init__(self):
        super(DirLineEdit, self).__init__()
        self.textChanged.connect(self.on_text_changed)
like image 155
falsetru Avatar answered Feb 28 '23 12:02

falsetru