2010-01-04 3 views
0

나는 약간의 어색한 행동을 보이고있는 콤보가 있습니다. 콤보 박스의 옵션 목록이 주어지면 사용자는 마우스로 클릭 한 도시의 이름을 선택해야합니다.Qt 파이썬 콤보 상자 "currentIndexChanged"두 번 실행

QtCore.QObject.connect(self.comboCity, QtCore.SIGNAL("currentIndexChanged(QString)"), self.checkChosenCity)     

def checkChosenCity(self): 
    self.cityName=self.comboCity.currentText() 
    print "the city chosen is:" 
    print "%s" % self.cityName 

문제는, 도시가 선택 될 때마다, connect 기능 checkChosenCity 두 번 호출 : 여기에 코드입니다.

이 콤보는 첫 번째 콤보에서 고객을 선택한 후 두 번째 콤보 상자에서 해당 고객에 대한 도시 목록이 제공되는 계층 적 콤보입니다.

여기 누군가가 이러한 일이 발생하는 이유를 지적하거나 추측 할 수 있기를 바랍니다. 내가 발견하는 것은 어떤 도시가 선택되지 않은 경우에도, 도시의 combox 박스가 활성화되고 있다는 점이다

combo1 : [customernames] - pick a customer. 
combo2 : [cityList] - pick a city for the chosen customer. 
combo3 : [emploeeList] - load employees for that city, given the chosen customer. 

:

+0

문제를 설명하는 작은 예제를 모두 분리하십시오. –

답변

-1

감사 엘리 .. 여기

내가 가진 것입니다. 그리고 네, 함수 'checkChosenCity'가 프로그램 내의 다른 곳에서 호출되지 않았는지 확인했습니다.

이상적인 해결책이 아닌 빠른 수정으로 문제를 피하기 위해 'checkChosenCity'함수를 사용했습니다. 따라서이 함수가 'connect'에 의해 잘못 활성화되면 도시 이름이 실제로 선택되었는지 확인한 다음 도시 이름이없는 경우 뾰족한 프로세스가 실행되지 않아 시스템 충돌을 피할 수 있습니다.

다음
def loadComboCustomer(self): 
    """queries customerList into self.connexDB.matrix""" 
    self.loadCustomerList_mysql() 

    lin=0 
    """ the data is imported from mysql class into self.db.matrix""" 
    for row in self.connexDB.matrix: 
     id=lin 
     customername=self.connexDB.matrix[lin][0] 
     self.addcomboCustomer(id,customername) 
     lin=lin+1 

은 다음과 같습니다

def loadcomboCity(self,customerName): 
    if customerName == " ": 
     """no customer was chosen yet - list of city empty""" 
    id=0 
     CityName=" " 
     self.addcomboCity(id,CityName) 
    else: 
     """for this customerName - load his city list""" 
     self.loadCityList_mysql(customerName) 

    lin=0 
    """ the data is imported from mysql class into self.db.matrix""" 
     for row in self.db.matrix: 
      id=lin 
      cityname=self.db.matrix[lin][0] 
      print "city name = %s" % cityname 
      self.addcomboCity(id,cityname) 
      lin=lin+1 

가 콤보 상자에 고객 이름 목록을로드하는 기능입니다 : 여기

은 콤보 상자에 도시 목록을로드하는 기능입니다 고객 이름이 선택되었는지 검사하는 함수 :

def checkChosenCustomer(self): 
    self.customerName=self.comboCustomer.currentText() 
    print "the customer chosen is:" 
    print "%s" % self.customerName 

    self.loadcomboCity(self.customerName) 

콤보 상자에 목록에서 선택 일부 도시 : 정말

def options(self): 
    self.comboCustomer = QtGui.QComboBox(self.boxBooking) 
    self.comboCustomer.setGeometry(QtCore.QRect(60, 60, 521, 22)) 

    self.loadComboCustomer() 
    QtCore.QObject.connect(self.comboCustomer, QtCore.SIGNAL("currentIndexChanged(QString)"), self.checkChosenCustomer) 

    self.comboCity = QtGui.QComboBox(self.boxBooking) 
    self.comboCity.setGeometry(QtCore.QRect(60, 120, 521, 22)) 

    self.loadcomboCity(self.customerName) 
    QtCore.QObject.connect(self.comboCity, QtCore.SIGNAL("currentIndexChanged(QString)"), self.checkChosenCity) 

하지 이상적인 솔루션 : 여기

def checkChosenCity(self): 
    self.CityName=self.comboCity.currentText() 
    print "the City chosen is:" 
    print "value of City = %s" % self.CityName 

    if self.CityName == '': 
     print "empty" 
    else: 
     """for this city - load the respective customer employee list""" 
     self.buildListOfEmployees_mysql(self.CityName) 

    """ the data is imported from mysql class into self.db.matrix""" 
     for row in self.db.matrix: 
      id=lin+1 
      personname=self.db.matrix[lin][0] 
      print "person name = %s" % personname 
      self.addcomboPerson(id,personname) 
      lin=lin+1 

콤보 박스 이벤트를 연결하는 주요 기능입니다. 그러나 이상한 연결 이벤트가 잘못 작동되고 있음을 알아내는 데 몇 시간을 소비해야한다는 것은 상당히 재미 있습니다.

다른 설명을 발견하면 저희에게 알려주십시오.

0

나는 정확히 같은 문제가있었습니다. 디버깅 후에는

currentIndexChanged (INT) 대신

currentIndexChanged (QString)의

을 사용하여

나 그것을 고정하는 것이 밝혀졌다.

아직도 전이 두 번 발생하는 이유는 아직 이해가되지 않습니다.