Qtexample.py

I’m hoping to put together a simple GUI with PyQt with embedded histograms and canvases using PyROOT. I was thinking that the example in:
$ROOTSYS/tutorials/pyroot/qtexample.py
would be a good starting place, but I cannot get it to work. Am I missing something from my environment?

[pc-penn-d-03] ~ >> cd $ROOTSYS/tutorials/pyroot/
[pc-penn-d-03] pyroot >> python -i qtexample.py
Message: (file "/afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00/slc4_ia32_gcc34/root/lib/libGQt.so", line 1) dlopen error: libQtCore.so.4: cannot open shared object file: No such file or directory
Error in <TCint::AutoLoad>: failure loading library libGQt.so for class TQtRootSlot
/afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00/slc4_ia32_gcc34/root/lib/ROOT.py:398: RuntimeWarning: tp_compare didn't return -1 or -2 for exception
  if type(attr) == _root.PropertyProxy:
Traceback (most recent call last):
  File "qtexample.py", line 44, in <module>
    terminator = ROOT.TQtRootSlot.CintSlot()
  File "/afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00/slc4_ia32_gcc34/root/lib/ROOT.py", line 372, in __getattr1
    return getattr( self, name )
  File "/afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00/slc4_ia32_gcc34/root/lib/ROOT.py", line 398, in __getattr2
    if type(attr) == _root.PropertyProxy:
RuntimeError: (file "/afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00/slc4_ia32_gcc34/root/lib/libGQt.so", line 1) Failed to load Dynamic link library /afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00/slc4_ia32_gcc34/root/lib/libGQt.so
>>>
[pc-penn-d-03] pyroot >> echo $ROOTSYS
/afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00/slc4_ia32_gcc34/root
[pc-penn-d-03] pyroot >> echo $PYTHONPATH
/afs/cern.ch/sw/lcg/external/pyqt/3.17.3_python2.5/slc4_ia32_gcc34/lib/python2.5/site-packages:/afs/cern.ch/sw/lcg/external/sip/4.7.9_python2.5/slc4_ia32_gcc34/lib/python/2.5/site-packages:/usr/lib/oracle/10.2.0.1/client/lib:/afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00/slc4_ia32_gcc34/root/pyroot:/afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00/slc4_ia32_gcc34/root/lib:/afs/cern.ch/user/r/reece/code/python/modules:/afs/cern.ch/user/r/reece/code/python/modules/MetaROOT:/afs/cern.ch/sw/lcg/external/pyqt/3.17.3_python2.5/slc4_ia32_gcc34/lib/python2.5/site-packages:/afs/cern.ch/sw/lcg/external/sip/4.7.9_python2.5/slc4_ia32_gcc34/lib/python/2.5/site-packages:/usr/lib/oracle/10.2.0.1/client/lib:/afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00/slc4_ia32_gcc34/root/pyroot:/afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00/slc4_ia32_gcc34/root/lib:/afs/cern.ch/user/r/reece/code/python/modules:/afs/cern.ch/user/r/reece/code/python/modules/MetaROOT:
[pc-penn-d-03] pyroot >> echo $LD_LIBRARY_PATH
/usr/lib/oracle/10.2.0.1/client/lib:/afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00/slc4_ia32_gcc34/root/lib:/afs/cern.ch/sw/lcg/external/Python/2.5/slc4_ia32_gcc34/lib:/usr/lib/oracle/10.2.0.1/client/lib:/afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00/slc4_ia32_gcc34/root/lib:/afs/cern.ch/sw/lcg/external/Python/2.5/slc4_ia32_gcc34/lib:

As you can see from the evnironment variables that I printed out, I am using ROOT 5.22 through afs at CERN, on SCL4. I found various versions of pyqt in /afs/cern.ch/sw/lcg/external/pyqt/ and added version 3.17.3_python2.5 to my PYTHON path along with sip/4.7.9_python2.5, because something called sip is used in the qtexample.py.

Thanks for your help.

Ryan,

well, one thing seems obvious in that the ROOT version used was build against Qt4, whereas the libraries provided are Qt3. The /afs directory that you quote has Qt4 as well, so I’d start with that.

In addition, thanks to Zoltan and Valeri, there’s an update to qtexample.py, and although it’s not in 5.22 it does appear to be in trunk, so pick that one up as well.

HTH,
Wim

Hi Wim,

Thanks for the reply. I switched to using PyQt4

export PYTHONPATH=/afs/cern.ch/sw/lcg/external/pyqt/4.4.4_python2.5/slc4_ia32_gcc34/lib/python2.5/site-packages:$PYTHONPATH

and I coppied the head version of qtexample.py from the ROOT svn:
https://lxbuild091.cern.ch/svn/root/trunk/tutorials/pyroot/qtexample.py

but it still fails:

[pc-penn-d-03] ~ >> python -i qtexample.py
Message: (file "/afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00/slc4_ia32_gcc34/root/lib/libGQt.so", line 1) dlopen error: libQt3Support.so.4: cannot open shared object file: No such file or directory
Error in <TCint::AutoLoad>: failure loading library libGQt.so for class TQtRootSlot
/afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00/slc4_ia32_gcc34/root/lib/ROOT.py:398: RuntimeWarning: tp_compare didn't return -1 or -2 for exception
  if type(attr) == _root.PropertyProxy:
Traceback (most recent call last):
  File "qtexample.py", line 46, in <module>
    terminator = ROOT.TQtRootSlot.CintSlot()
  File "/afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00/slc4_ia32_gcc34/root/lib/ROOT.py", line 372, in __getattr1
    return getattr( self, name )
  File "/afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00/slc4_ia32_gcc34/root/lib/ROOT.py", line 398, in __getattr2
    if type(attr) == _root.PropertyProxy:
RuntimeError: (file "/afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00/slc4_ia32_gcc34/root/lib/libGQt.so", line 1) Failed to load Dynamic link library /afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00/slc4_ia32_gcc34/root/lib/libGQt.so

Does libQt3Support.so.4 indicate that I should be using PyQt3?

Ryan,

no, that library seems to be a Qt3 compatibility library that is part of Qt4. Rather, I think that the LD_LIBRARY_PATH envar in your setup does not contain an entry for the Qt libraries. They are also on the same location, for example here:

/afs/cern.ch/sw/lcg/external/qt/4.4.2/slc4_ia32_gcc43/lib

I don’t know which would be the exact version of Qt4 that you need, though …

Cheers,
Wim

Thanks for following this up with me Wim. I added the path you mention to my LD_LIBRARY_PATH. Now I get the following failure.

[lxplus216] ~ >> python -i qtexample.py 
TClass::TClass:0: RuntimeWarning: no dictionary for class QObject is available
Traceback (most recent call last):
  File "qtexample.py", line 48, in <module>
    QObject.connect(application, SIGNAL("lastWindowClosed()"),termAddress ,SLOT("Terminate()"))
RuntimeError: underlying C/C++ object has been deleted

I thought I could learn something from this related thread:
http://root.cern.ch/phpBB2/viewtopic.php?t=4565
but it is unclear what the resolution was. I am not doing anything to setup QtROOT. Is it not possible to just directly use PyROOT and PyQt4 glued together in Python?

Ryan,

did you setup QtRoot in your .rootrc? IIRC, that was:

Gui.Backend: qt Gui.Factory: qtgui Plugin.TGuiFactory: qtgui TQtRootGuiFactory QtRoot "TQtRootGuiFactory()"
As for mixing directly PyQt and PyROOT, yes that is in principle no problem, except that ROOT graphics objects will not be plottable on Qt windows and vice versa. For that, you’d need QtRoot.

Cheers,
Wim

Wim,

Now I’m getting somewhere. I appologize that I didn’t read the rootrc setup in the ROOT manual. Now that I’ve done that, qtexample.py runs, except I cannot get it to close.

[pc-penn-d-03] ~ >> python qtexample.py
** $Id: TGQt.cxx 26689 2008-12-06 07:03:04Z brun $ this=0xa272d88
Symbol font family found: Standard Symbols L
Using rootlogon.py
TClass::TClass:0: RuntimeWarning: no dictionary for class QObject is available
TClass::TClass:0: RuntimeWarning: no dictionary for class QWidget is available
Bye bye...

After I click the Quit button, the window closes and it prints the above ‘Bye bye…’. But then it hangs there, with no response to C-c or C-d. Note that it never prints ‘Bye forever!’, which the script seems to indicate that it should at the end.

Ryan,

yes, it appears that a ROOT.gApplication.Terminate() is needed (or something similar; this seemed to be the best I could find), to jump out of the Run() loop. Also, the Qt canvas that gets put to the TQtWidget results in an ownership issue, that won’t show up until shutdown.

I’ve fixed both in trunk.

As an aside, use C-\ (that is, SIGQUIT), will kill the application if it hangs.

HTH,
Wim