[PyQt] Another connect problem
Jason H
scorp1us at yahoo.com
Thu Oct 1 19:56:17 BST 2009
The C++ code uses new to create an object on the heap, which you must delete later
In python if nothing references the object, it is destroyed. So as soon as __init__ is done, job goes *poof*
You need to maintain a reference to it by using self.job = ... so that way the class keeps the job instance around.
----- Original Message ----
From: Thomas Olsen <tanghus at gmail.com>
To: pyqt at riverbankcomputing.com; Jason H <scorp1us at yahoo.com>
Sent: Thursday, October 1, 2009 2:46:48 PM
Subject: Re: [PyQt] Another connect problem
On Thursday 01 October 2009 20:22:00 Jason H wrote:
> job is not a member of the class (self.job) so it gets destroyed.
>
So should it be:
def job_recieved(self, data):
print "Data recieved: " + data
I was looking at the example:
#include <kio/scheduler.h>
#include <kurl.h>
#include <kio/jobclasses.h>
#include <kdebug.h>
#include <browser.h>
class TransferJob;
Browser::Browser() : QWidget(NULL)
{
slotButtonClicked();
}
void Browser::slotButtonClicked()
{
kDebug() << "entering function";
// creating a kioslave
KIO::TransferJob *job = KIO::get(KUrl("http://www.kde.org"));
connect (job, SIGNAL( data(KIO::Job *, const QByteArray & )), this,
SLOT(dataIsHere(KIO::Job *,const QByteArray &)));
}
void Browser::dataIsHere(KIO::Job *,const QByteArray & data )
{
kDebug() << "data is here";
kDebug() << data;
}
from
http://techbase.kde.org/Development/Tutorials/KIO_Slaves/Using_KIO_Slaves_in_your_Program
and there job is an argument to the slot..?
>
>
> ----- Original Message ----
> From: Thomas Olsen <tanghus at gmail.com>
> To: pyqt at riverbankcomputing.com
> Sent: Thursday, October 1, 2009 2:09:21 PM
> Subject: [PyQt] Another connect problem
>
> Hi
>
> This is actually PyKDE4 related but the list seems to be dead.
>
> I am trying to connect a KIO.TransferJob[1] to a method in my class but
> must be doing something wrong. A very stripped down version of my class
> looks like this:
>
> from PyKDE4.kdecore import *
> from PyKDE4.kio import *
>
> class MyClass():
> def __init__(self):
> job = KIO.get(KUrl("http://somesite.com"))
> QObject.connect(job, SIGNAL("data(Job*, const QByteArray&)"),
> self.job_received)
>
> def job_received(self, job, data):
> print "Data received: " + data
>
>
> But job_received is never called. I know I should be using the new-style
> connect but I haven't really grasped it yet...
>
> [1] http://api.kde.org/pykde-4.3-api/kio/KIO.TransferJob.html
>
--
Best Regards / Med venlig hilsen
Thomas Olsen
Til uvedkommende, der læser med: Der er ingen grund til at læse min mail.
Jeg har intet at gøre med FARC, al-Jihad, al-Qaida, Hamas, Hizb al-Mujahidin
eller ETA.
Jeg har aldrig gjort Zakat, går ikke ind for Istishad, har ikke lavet en
bilbombe eller kernevåben og jeg ved dårligt nok, hvad Al Manar og бомба
betyder.
Men tak for den udviste interesse
More information about the PyQt
mailing list