开发者

PyQt4 problem with xml database browser (treeview, singals and insertplaintext)

开发者 https://www.devze.com 2023-02-28 02:32 出处:网络
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 wi

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.S开发者_JAVA技巧LOT("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:

self.ui.treeView.clicked.connect(self.ui.plainTextEdit.paste)

Now, paste is a method accepting a single argument, and this argument is of the type the clicked signal of self.ui.treeView sends. 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 () after test. 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 data method. Read the doc for QModelIndex

0

精彩评论

暂无评论...
验证码 换一张
取 消