Sep 3, 2009

QStrings and Strings

In Qt, QFileDialog can be used to open up a filedialog window. QFileDialog's static methods allows the GUI to capture the directory/file name that the user chooses. From that, a QString is returned.

My problem was that I wanted to find a certain string in the filename, but it was a QString, and not a string. I found that...

to convert a qstring to string, use the str function.

stringB = str(stringA)

In this situation, stringB will be the string version of stringA, which is of type QString. By the way, str works on integers as well.

PyQt Documentation on Qfiledialog