Convert QStingList to Python list

P

Peter Chant

The following code generates a QStringList:

fileNames = QFileDialog.getOpenFileNames(None,"Chose raw file",".",)

Printing it:

print "Files selected "+QStringList(fileNames)

Results in:

TypeError: cannot concatenate 'str' and 'QStringList' objects

Any idea how to convert a QStingList into a python list? pythonQtConv seems
to come up in google but I've no idea how to import or invoke it.

Thoughts?

Pete
 
P

Peter Otten

Peter said:
The following code generates a QStringList:

fileNames = QFileDialog.getOpenFileNames(None,"Chose raw file",".",)

Printing it:

print "Files selected "+QStringList(fileNames)

You say that fileNames already is a QStringList. Why are you trying to
convert it to a QStringList then?
Anyway, it wouldn't work with a python list either.
Results in:

TypeError: cannot concatenate 'str' and 'QStringList' objects

Any idea how to convert a QStingList into a python list? pythonQtConv
seems to come up in google but I've no idea how to import or invoke it.

Thoughts?

Try it out yourself in the interactive interpreter. Here's a sample session:
files = QStringList(["alpha.txt", "beta.txt"])
print files
print list(files) [PyQt4.QtCore.QString(u'alpha.txt'), PyQt4.QtCore.QString(u'beta.txt')]
print [str(f) for f in files] ['alpha.txt', 'beta.txt']
print "Selected files:", ", ".join(str(f) for f in files) Selected files: alpha.txt, beta.txt
files = QStringList([u"äöü.txt", "beta.txt"])
print "Selected files:", ", ".join(str(f) for f in files)
Selected files:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 1, in <genexpr>
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-2:
ordinal not in range(128)Selected files: äöü.txt, beta.txt

Peter
 
P

Peter Chant

Peter said:
Try it out yourself in the interactive interpreter. Here's a sample
session:

Peter,

thanks. I've got some way to go with python and have only just started
looking at Qt, your help has been very useful.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top