I’m writing a database browser application with PyQt4 and because I’m new to Qt, I have some problems. I have most functionalities already written in python but know I’m trying to implement them with PyQt4 GUI.
First of all my application now looks like this:
Browser
In these catalogues I have xml files which I would like to parse.
I’ve written something like this:
QtCore.QObject.connect(self.ui.treeView, QtCore.SIGNAL("clicked(QModelIndex)"), self.ui.plainTextEdit, QtCore.SLOT("paste()"))
and it works. But when I’m trying to do something like this:
QtCore.QObject.connect(self.ui.treeView, QtCore.SIGNAL("clicked(QModelIndex)"), self.ui.plainTextEdit, QtCore.SLOT("insertPlainText('test')"))
it fails. After reading the manual I know that SIGNAL and SLOT must take the same arguments. So I should write some signal which executes a SLOT which is a function with QModelIndex argument which finds clicked file, creates the xmldocument object and then prints out it’s dictionaries.
My questions are:
- How can I create such function which is callable as SLOT?
Because inside ui file I created a function:
def test(self):
print "Debug"
And when I’m trying to call it out
QtCore.QObject.connect(self.ui.treeView, QtCore.SIGNAL("clicked(QModelIndex)"), self.ui.test())
I’m getting this error:
TypeError: arguments did not match any overloaded call:
QObject.connect(QObject, SIGNAL(), QObject, SLOT(), Qt.ConnectionType=Qt.AutoConnection): argument 3 has unexpected type 'NoneType'
QObject.connect(QObject, SIGNAL(), callable, Qt.ConnectionType=Qt.AutoConnection): argument 3 has unexpected type 'NoneType'
QObject.connect(QObject, SIGNAL(), SLOT(), Qt.ConnectionType=Qt.AutoConnection): argument 2 has unexpected type 'str'
And another question:
- How should I get path to clicked file from QModelIndex?
Consider using the new-style connection mechanism provided by PyQt:
Now,
pasteis a method accepting a single argument, and this argument is of the type theclickedsignal ofself.ui.treeViewsends. Dissect if from there, as you wish.How can I create such function which is callable as SLOT?
It’s a different error. You connect to
self.ui.test(), but this is a function call, not a function. Remove the()aftertest. But better yet, use the new-style connection mechanism as described above.How should I get path to clicked file from QModelIndex?
Probably by calling its
datamethod. Read the doc forQModelIndex