[PyKDE] Using QFileDialog

Phil Thompson phil at riverbankcomputing.co.uk
Mon Jan 9 19:39:59 GMT 2006


On Monday 09 January 2006 7:27 pm, Baz Walter wrote:
> On Monday 09 Jan 2006 16:12, piotr maliński wrote:
> > I'm learning pyQT and I have a problem with QFileDialog - how can I
> > get the selected filename? I've made a simple form: a pushbutton that
> > onlick runs function "test" which opens the filedialog (in
> > qtdesigner):
> > ------------------------------
> > void Form1::test()
> > {
> > a = QFileDialog(self)
> > QObject.connect(a, SIGNAL('fileSelected()') ,self , SLOT('test2()'))
> > a.show()
> > }
> > -------------------------------
> > But when the widgets shows i get:
> > QObject::connect: No such signal QFileDialog::fileSelected()
> > QObject::connect:  (sender name:   'unnamed')
> > QObject::connect:  (receiver name: 'Form1')
> >
> > test2 function looks like this:
> > --------------------------------------
> > void Form1::test2()
> > {
> > self.pushButton1.setText("aaaaaa")
> > }
> > --------------------------------------
> > 1. how can I make it work?
> > 2. how can I get the selected filename and display its name as
> > pushButton1 text? Will something like: SLOT("test2(a.selectedFile())")
> > work?
>
> SLOT is only needed for pre-defined qt slots. When connecting to slots you
> have created yourself, pass the python function object instead, like this:
>
> 	void Form1::test()
> 	{
> 	a = QFileDialog(self)
> 	QObject.connect(a, SIGNAL('fileSelected(const QString&)'), self.test2)
> 	a.show()
> 	}

Actually SLOT() isn't needed at all because each Qt slot has a corresponding 
Python method anyway. However, it is more efficient to use it because then 
everything happens at the Qt/C++ level.

Phil




More information about the PyQt mailing list