[PyQt] pyqt book and first example

Mark Summerfield mark at qtrac.eu
Wed Apr 9 07:52:39 BST 2008


On 2008-04-08, FarSight Data Systems wrote:
> I'm trying to go through the book and the first example is not working
> properly.
>
> I've installed pyqt4 via adept on my Kubuntu Feisty Fawn laptop.

Which versions of Python, Qt, and PyQt are on your system?

How exactly is the example failing?

BTW the code you've reproduced here is incomplete, there should be more
lines at the end. (See eg/chap04/alert.pyw in the examples, or page 114
of the book.)

The "due" object that you're printing out is exactly what I'd expect. It
is unfortunate (and annoying) that many simple PyQt data types have the
same repr() and str() strings when for the latter they could produce
something nicer. Try replacing
    print due
with
    print str(due.toString())
And try running the program with a time that's just gone so that the
message pops up immediately.

> The first example in the qt section of the books is as follows:
>
> code follows -------------------------------------
>
> #!/usr/bin/env python
>
> import sys
> import time
> from PyQt4.QtCore import *
> from PyQt4.QtGui import *
>
> app = QApplication(sys.argv)
>
> try:
>         due = QTime.currentTime()
>         message = "Alert!"
>         
>         if len(sys.argv) < 2:
>                 raise ValueError
>         hours, mins = sys.argv[1].split(":")
>         due = QTime(int(hours), int(mins))
>         print due
>         if not due.isValid():
>                 print "due is not valid"
>                 raise ValueError
>         else:
>                 print "due is valid"
>         
>         if len(sys.argv) > 2:
>                 message = " ".join(sys.argv[2:])
> except ValueError:
>         message = "Usage: alert.pyw HH:MM [optional message]" # 24hr clock
>                 
> code ended -------------------------------------
>
> I've added a couple of print lines to get the values of some variable to
> see what they are.  The one that strikes me the most is due, the value
> returned from that isn't time.  It's
>
> <PyQt4.QtCore.QTime object at 0xb7d13e6c>
>
> Can anyone explain the problem I'm having here?
>
> Thanks
>
> Mark
>
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt



-- 
Mark Summerfield, Qtrac Ltd., www.qtrac.eu




More information about the PyQt mailing list