QNetworkReply pyQt

classic Classic list List threaded Threaded
16 messages Options
Reply | Threaded
Open this post in threaded view
|

QNetworkReply pyQt

Christopher Probst

new to pyQt and I am stumped. I am trying to get the QNetworkAccessManager class to work with these lines
class Download(QNetworkAccessManager):
..
self.m_reply = self.get(QNetworkRequest(QUrl("http://download.qt.io/official_releases/qt/5.8/5.8.0/single/qt-everywhere-opensource-src-5.8.0.tar.gz")))

self.m_reply.readyRead.connect(self.debugging)
self.m_reply.error.connect(self.debugging)
self.m_reply.finished.connect(self.debugging)
..

where debugging is a slot
@pyqtSlot()
def debugging(self):
print("downloadProgress")

Problem is, it looks as if the readyRead, error or finished signal are never emitted. What am I doing wrong?

Thanks,
Christopher


_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: QNetworkReply pyQt

Tony Arnold
Chris,


On Wed, 2017-05-03 at 10:53 -0400, Christopher Probst wrote:

>
> new to pyQt and I am stumped. I am trying to get the
> QNetworkAccessManager class to work with these lines
> class Download(QNetworkAccessManager):
> ..
> self.m_reply = self.get(QNetworkRequest(QUrl("http://download.qt.io/o
> fficial_releases/qt/5.8/5.8.0/single/qt-everywhere-opensource-src-
> 5.8.0.tar.gz")))
>
> self.m_reply.readyRead.connect(self.debugging)
> self.m_reply.error.connect(self.debugging)
> self.m_reply.finished.connect(self.debugging)
> ..
>
> where debugging is a slot
> @pyqtSlot()
> def debugging(self):
>     print("downloadProgress")
>
> Problem is, it looks as if the readyRead, error or finished signal
> are never emitted. What am I doing wrong?
I would  check the value of self.m_reply.error() immediately after the
get call. It may be possible that an error can occur before the signals
get connected.

Regards,
Tony.
--
Tony Arnold MBCS, CITP | Senior IT Security Analyst | Directorate of IT Services | G.110, Kilburn Building | The University of Manchester | Manchester M13 9PL | T: +44 161 275 6093 | M: +44 773 330 0039

_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt

smime.p7s (6K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: QNetworkReply pyQt

Florian Bruhin
In reply to this post by Christopher Probst
Hi,

On Wed, May 03, 2017 at 10:53:37AM -0400, Christopher Probst wrote:
> Problem is, it looks as if the readyRead, error or finished signal are
> never emitted. What am I doing wrong?

Hard to say without a working example - I think it'd also be possible
that the readyRead signal is emitted before you connect the slot. Then
it's never emitted again (and neither are the others) because you never
read anything from the reply.

Florian

--
https://www.qutebrowser.org  | [hidden email] (Mail/XMPP)
   GPG: 916E B0C8 FD55 A072  | https://the-compiler.org/pubkey.asc
         I love long mails!  | https://email.is-not-s.ms/

_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: QNetworkReply pyQt

Andreas Pakulat
Hi,

On Wed, May 3, 2017 at 5:33 PM, Florian Bruhin <[hidden email]> wrote:

> Hi,
>
> On Wed, May 03, 2017 at 10:53:37AM -0400, Christopher Probst wrote:
>> Problem is, it looks as if the readyRead, error or finished signal are
>> never emitted. What am I doing wrong?
>
> Hard to say without a working example - I think it'd also be possible
> that the readyRead signal is emitted before you connect the slot. Then
> it's never emitted again (and neither are the others) because you never
> read anything from the reply.

The behavior of at least the finished signal has recently been
discussed on the qt list. Since using a QNetworkReply in the way the
OP does is perfectly valid its guaranteed by Qt that the 'finished'
signal is always emitted even if you connect it after you 'started'
the network request. So in the scenario outlined at least the finished
signal should be emitted for sure.

Hence a complete example would be useful.

Andreas
_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: QNetworkReply pyQt

Christopher Probst
In reply to this post by Christopher Probst

So I tried this self-contained example from the documentation, the finished signal is never emitted. What am I doing wrong? I am using pyQt5 and python 3.5.


import sys
from PyQt5.QtWidgets import QApplication
from PyQt5.QtNetwork import *
from PyQt5.QtCore import *
from downloadmgrWidget import DownloadManagerWidget

class DebugginClass(QObject):
def __init__(self, parent=None):
QObject(parent)

@pyqtSlot()
def debugging(self):
print("Signal finished emitted")


if __name__ == "__main__":
app = QApplication(sys.argv)


debugClass = DebugginClass()
manager = QNetworkAccessManager()

manager.finished['QNetworkReply*'].connect(debugClass.debugging)

manager.get(QNetworkRequest(QUrl("http://qt.nokia.com")));


sys.exit(app.exec_())

_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: QNetworkReply pyQt

Christopher Probst
I am going to send the example again without a dependency to my project. For some odd reason the finished signal is never received.

import sys

from PyQt5.QtWidgets import QApplication
from PyQt5.QtNetwork import *
from PyQt5.QtCore import * 
class DebugginClass(QObject):
    def __init__(self, parent=None):
        QObject(parent)

    @pyqtSlot()
    def debugging(self):
        print("Signal finished emitted")


if __name__ == "__main__":
    app = QApplication(sys.argv)


    debugClass = DebugginClass()
    manager = QNetworkAccessManager()

    manager.finished['QNetworkReply*'].connect(debugClass.debugging)

    manager.get(QNetworkRequest(QUrl("http://qt.nokia.com")));


    sys.exit(app.exec_())

On Wed, May 3, 2017 at 12:10 PM, Christopher Probst <[hidden email]> wrote:

So I tried this self-contained example from the documentation, the finished signal is never emitted. What am I doing wrong? I am using pyQt5 and python 3.5.


import sys
from PyQt5.QtWidgets import QApplication
from PyQt5.QtNetwork import *
from PyQt5.QtCore import *
from downloadmgrWidget import DownloadManagerWidget

class DebugginClass(QObject):
def __init__(self, parent=None):
QObject(parent)

@pyqtSlot()
def debugging(self):
print("Signal finished emitted")


if __name__ == "__main__":
app = QApplication(sys.argv)


debugClass = DebugginClass()
manager = QNetworkAccessManager()

manager.finished['QNetworkReply*'].connect(debugClass.debugging)

manager.get(QNetworkRequest(QUrl("http://qt.nokia.com")));


sys.exit(app.exec_())


_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: QNetworkReply pyQt

Phil Thompson-5
On 03/05/2017 17:15, Christopher Probst wrote:

> I am going to send the example again without a dependency to my
> project.
> For some odd reason the finished signal is never received.
>
> import sys
>
> from PyQt5.QtWidgets import QApplication
> from PyQt5.QtNetwork import *
> from PyQt5.QtCore import *
>
> class DebugginClass(QObject):
>     def __init__(self, parent=None):
>         QObject(parent)

This is Python not C++.

Phil
_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: QNetworkReply pyQt

Christopher Probst
Sorry I am confused here. This is a pyQt mailing list and I am putting a python 3.5 example which does not seem to work on my end. I am merely asking what I am doing wrong?

On Wed, May 3, 2017 at 1:02 PM, Phil Thompson <[hidden email]> wrote:
On 03/05/2017 17:15, Christopher Probst wrote:
I am going to send the example again without a dependency to my project.
For some odd reason the finished signal is never received.

import sys

from PyQt5.QtWidgets import QApplication
from PyQt5.QtNetwork import *
from PyQt5.QtCore import *

class DebugginClass(QObject):
    def __init__(self, parent=None):
        QObject(parent)

This is Python not C++.

Phil


_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: QNetworkReply pyQt

Florian Bruhin
On Wed, May 03, 2017 at 01:17:12PM -0400, Christopher Probst wrote:
> Sorry I am confused here. This is a pyQt mailing list and I am putting a
> python 3.5 example which does not seem to work on my end. I am merely
> asking what I am doing wrong?

QObject(parent) is (similar to) what you'd do in C++, but does nothing
useful in Python.

You want something like  super().__init__(parent)  or
QObject.__init__(self, parent)  instead.

See e.g.:
https://www.blog.pythonlibrary.org/2014/01/21/python-201-what-is-super/

Florian

--
https://www.qutebrowser.org  | [hidden email] (Mail/XMPP)
   GPG: 916E B0C8 FD55 A072  | https://the-compiler.org/pubkey.asc
         I love long mails!  | https://email.is-not-s.ms/

_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: QNetworkReply pyQt

Damon Lynch
In reply to this post by Christopher Probst


On Wed, May 3, 2017 at 12:17 PM, Christopher Probst <[hidden email]> wrote:
Sorry I am confused here. This is a pyQt mailing list and I am putting a python 3.5 example which does not seem to work on my end. I am merely asking what I am doing wrong?

Use super(), not a call to QObject. See: https://rhettinger.wordpress.com/2011/05/26/super-considered-super/

FWIW it's typically good practice to start your reply inline rather than at the top of the message. Makes following things easier.

_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: QNetworkReply pyQt

Andreas Pakulat
In reply to this post by Andreas Pakulat
Hi,

On Wed, May 3, 2017 at 6:07 PM, Andreas Pakulat <[hidden email]> wrote:

> Hi,
>
> On Wed, May 3, 2017 at 5:33 PM, Florian Bruhin <[hidden email]> wrote:
>> Hi,
>>
>> On Wed, May 03, 2017 at 10:53:37AM -0400, Christopher Probst wrote:
>>> Problem is, it looks as if the readyRead, error or finished signal are
>>> never emitted. What am I doing wrong?
>>
>> Hard to say without a working example - I think it'd also be possible
>> that the readyRead signal is emitted before you connect the slot. Then
>> it's never emitted again (and neither are the others) because you never
>> read anything from the reply.
>
> The behavior of at least the finished signal has recently been
> discussed on the qt list. Since using a QNetworkReply in the way the
> OP does is perfectly valid its guaranteed by Qt that the 'finished'
> signal is always emitted even if you connect it after you 'started'
> the network request. So in the scenario outlined at least the finished
> signal should be emitted for sure.

For reference this is the thread on the Qt mailinglist:

http://lists.qt-project.org/pipermail/interest/2017-April/026862.html

Andreas
_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: QNetworkReply pyQt

Baz Walter
In reply to this post by Christopher Probst
On 03/05/17 17:15, Christopher Probst wrote:
> For some odd reason the finished signal is never received.
>
>     def __init__(self, parent=None):
>         QObject(parent)

???

>
>     manager.get(QNetworkRequest(QUrl("http://qt.nokia.com")));

Hmm... nokia...

_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: QNetworkReply pyQt

Hans-Peter Jansen-2
In reply to this post by Christopher Probst
On Mittwoch, 3. Mai 2017 13:17:12 Christopher Probst wrote:

> Sorry I am confused here. This is a pyQt mailing list and I am putting a
> python 3.5 example which does not seem to work on my end. I am merely
> asking what I am doing wrong?
>
> On Wed, May 3, 2017 at 1:02 PM, Phil Thompson <[hidden email]>
>
> wrote:
> > On 03/05/2017 17:15, Christopher Probst wrote:
> >> I am going to send the example again without a dependency to my project.
> >> For some odd reason the finished signal is never received.
> >>
> >> import sys
> >>
> >> from PyQt5.QtWidgets import QApplication
> >> from PyQt5.QtNetwork import *
> >> from PyQt5.QtCore import *
> >>
> >> class DebugginClass(QObject):
> >>     def __init__(self, parent=None):
> >>         QObject(parent)

Make this:

        QObject.__init__(self, parent)

or

        super(DebugginClass, self).__init__(parent)

or some such...

> > This is Python not C++.

Phil can be curt up to touching your pain barrier.

Cheers,
Pete
_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: QNetworkReply pyQt

Phil Thompson-5
In reply to this post by Christopher Probst
On 03/05/2017 18:17, Christopher Probst wrote:
> Sorry I am confused here. This is a pyQt mailing list and I am putting
> a
> python 3.5 example which does not seem to work on my end. I am merely
> asking what I am doing wrong?

My apologies, you'll have to get used to my style.

I was trying to point out that the line of code to invoke the
super-class "ctor" was correct for C++ but wrong for Python.

Just remove the __init__ method and see what difference it makes.

Phil


> On Wed, May 3, 2017 at 1:02 PM, Phil Thompson
> <[hidden email]>
> wrote:
>
>> On 03/05/2017 17:15, Christopher Probst wrote:
>>
>>> I am going to send the example again without a dependency to my
>>> project.
>>> For some odd reason the finished signal is never received.
>>>
>>> import sys
>>>
>>> from PyQt5.QtWidgets import QApplication
>>> from PyQt5.QtNetwork import *
>>> from PyQt5.QtCore import *
>>>
>>> class DebugginClass(QObject):
>>>     def __init__(self, parent=None):
>>>         QObject(parent)
>>>
>>
>> This is Python not C++.
>>
>> Phil
>>

_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: QNetworkReply pyQt

Christopher Probst
In reply to this post by Baz Walter
Thanks for everybody's help. It does work. The error eventually was that the Download object that was doing all this stuff in a constructor was destroyed because it was stored in a local variable.

I decided to fix it by keeping it around with something like this 
self.download = Download()

I know, I know, this is a newbie mistake, thank-you for your patience.

Thanks,
Christopher

On Wed, May 3, 2017 at 2:51 PM, Baz Walter <[hidden email]> wrote:
On 03/05/17 17:15, Christopher Probst wrote:
For some odd reason the finished signal is never received.

    def __init__(self, parent=None):
        QObject(parent)

???


    manager.get(QNetworkRequest(QUrl("http://qt.nokia.com")));

Hmm... nokia...



_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: QNetworkReply pyQt

Barry Scott
In reply to this post by Christopher Probst


On 3 May 2017, at 18:17, Christopher Probst <[hidden email]> wrote:

Sorry I am confused here. This is a pyQt mailing list and I am putting a python 3.5 example which does not seem to work on my end. I am merely asking what I am doing wrong?

On Wed, May 3, 2017 at 1:02 PM, Phil Thompson <[hidden email]> wrote:
On 03/05/2017 17:15, Christopher Probst wrote:
I am going to send the example again without a dependency to my project.
For some odd reason the finished signal is never received.

import sys

from PyQt5.QtWidgets import QApplication
from PyQt5.QtNetwork import *
from PyQt5.QtCore import *

class DebugginClass(QObject):
    def __init__(self, parent=None):
        QObject(parent)

This not how you init the base class.

Try
            super().__init__( parent )

E.g write in python style not C++ style.


This is Python not C++.

Phil

_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt

_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt