Domanda

I've got a python script using PySide and it works fine. But then I thought to check if it gonna work with PyQt4. And after changing the import strings to PyQt4, things went wrong. The error points to the subject, as follows:

  File "./my_file.py", line 93, in showit
    curr_query = '.'.join(curr_query)
TypeError: sequence item 0: expected string, QString found

From the docs I can see that PySide subject method returns 'unicode' string, but the PyQt4 one returns QString object. Playing with the str(), str() etc did not seem to do the job. Here's the function code:

def showit(self, idx):
    curr_query = []
    for i in xrange(idx+1):
>>    x = self.combo[i].currentText()
>>    if x:
            curr_query.append(x)
        else:
            break
    curr_query = '.'.join(curr_query)

This reads text of a set of QCombobox'es to build up a dot-sepated string presentation that I use later. The marked '>>' lines is where the issue occurs - the 'x' object is never an empty string, suddenly, as it was while using PySide library. But it is expected to be empty, if there's an empty self.combo[i] .

I've searched the SO archive and found this answer but not able to use it. Please advice how to fix this.

È stato utile?

Soluzione

You need to convert your x values to a string of sorts. Something like

curr_query.append(str(x))

should do the trick.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top