QLineEdit will not change with QFileDialog (pyqt)
Some odd QLineEdit behavior... I want a QLineEdit to display the file path to an SQLite3 database.
txtdb is a QLineEdit
This changes the text perfectly:
Code:
txtdb.setText("foo")
This prints the filename as a string as expected:
Code:
def getdb():
return QtGui.
QFileDialog.
getOpenFileName(None,
"Select your database file",
"",
"SQLite 3 Databases (*.sq3)")
print getdb()
Put them together...
Code:
txtdb.setText(getdb())
..and the text just does not change! Even
Code:
a=getdb()
txtdb.setText(a)
is a total fail!
Anyone got any ideas how to fix this?
Rich
Re: QLineEdit will not change with QFileDialog (pyqt)
What is the type of "a" and what is the content of "a" in the last code snippet? Are you able to print a?
Re: QLineEdit will not change with QFileDialog (pyqt)
Hi,
Thanks for the reply.
Here's the most annoying thing: "print a" prints the file path perfectly! It just will not change the QLineEdit! I can't even think of a workaround.
Re: QLineEdit will not change with QFileDialog (pyqt)
But what is its type? It's probably not "QString instance", is it?
Re: QLineEdit will not change with QFileDialog (pyqt)
>>>> print type(a)
<class 'PyQt4.QtCore.QString'>
It was generated by QFileDialog::getOpenFileName, which returns a QString.
I'm stumped.:confused:
Re: QLineEdit will not change with QFileDialog (pyqt)
Solved! If I explicitly set it to a QString, it works perferctly.
wysota, you're a hero. Many thanks!