RE: RE: PyQt and PyROOT

From: Fine, Valeri <fine_at_bnl.gov>
Date: Fri, 12 Jan 2007 13:08:37 -0500


Hello Johan,

> 1) Where does this QtGui library comes from ? (there seems to be one
in
> qt4 but we do not have any in qt3)

> ** $Id: TGQt.cxx,v 1.35 2006/12/12 20:12:47 brun Exp $ this=0x9fc8d90
> Error in <TUnixSystem::DynamicPathName>: QtGui[.so | .sl | .dl | .a |
> .dll] does not exist in

The library in question is QtRoot library rather one from Qt4.

The simplest solution is to create a simlink between libQtRootGui.so and libQtGui.so.

I did choose the name "QtGui" for ROOT Qt extension a while ago, well BEFORE I learned about Qt 4 :((

Later on, I had to change the name of the library from QtGui to QtRootGui to be "Qt4 compliant". It looks like I missed some place to be fixed. I'll re-check things.

> 2) What is creating the 'other' QApplication ? (we instance only one
in
> the main !)

It is YOUR script !!! at the time your script calls "main". I guess there is another "real main" in Python,

> application = qt.QApplication(sys.argv)

ROOT had been started (QApplication was created too via ROOT Qt plug-in). May be, Wim can explain us at which point the PyROOT instantiates ROOT.

This means QtRoot "thinks" you (PyRoot application) are "Qt-based ROOT application" rather "ROOT-based Qt application" (see: ftp://root.cern.ch/root/doc/chapter27.pdf Section "Application" p 416).

Anyway, this merely means you should simplify your script to use qApp

( See: http://doc.trolltech.com/3.3/qapplication.html#QApplication "The QApplication object is accessible through the global pointer qApp")

instead of QApplication(sys.argv) and you must NOT enter the Qt Event loop at all.

Instead of your

> if __name__ == '__main__':
> application = qt.QApplication(sys.argv)
> qt.QObject.connect(application, qt.SIGNAL("lastWindowClosed()"),
> application, qt.SLOT("quit()"))
> w = window()
> w.show()
> application.exec_loop()

you need something like this

 if __name__ == '__main__':

    application = qt.qApp
    qt.QObject.connect(application, qt.SIGNAL("lastWindowClosed()"),  application, qt.SLOT("quit()"))

    w = window()
    w.show()

This may fix your next concern too:

> + If we add the histogram directly to the 'MainWindow' it's working,
> but we obviously need the 'layout' step to work.


> 3) We're now loading the 'qtcint' dictionary, so why some Qt class
> dictionaries are still missing ?

This library does not provide the dictionary for ALL Qt classes. See the Web page again
http://root.bnl.gov/QtRoot/htmldoc/src/qtclasses.h.html

It does provide the dictionary for the "Main classes", those I think one would want to use on the script (ROOT macro) level. I think this assertion is still correct for the Python scripts. Anyway the list of the Qt classes the RootCint dictionary built for is defined by the file http://root.cern.ch/viewcvs/cint/lib/qt/qtclasses.h?rev=1.9&content-type =text/vnd.viewcvs-markup

In fact, I think, the creating and loading qtcint.dll to make PyQt + PyROOT work together is unnecessary heavy solution.

What, I think one needs, is, in fact, some sort of the 4 automatic "cast" (a'la C++ cast operator ) operators,   To map "automatically":

    qt.QWidget <--> root.QWidget
    qt.QPixmap <--> root.QPixmap
    qt.QImage  <--> root.QImage 
    qt.QWidget <--> root.TQtWidget

This should be sufficient and I hope it can be achieved with no qtcint.

In fact I do not think one needs any QWidget, QPixmap etc ROOT dictionaries either.
For example, if one wants to invoke some TQtWidget methods inherited from the base QWidget he/she can do "cast"

 qt.QWidget = root.TQtWidget

and then invoke all QWidget methods via qt.QWidget. The same should be true for all other Qt classes.

Alas, I do not know Python and can not suggest the technical solution for this idea.

I hope I have answered all you current questions.

 I am waiting for the next one ;)

  Have a nice day, Valeri Fine


> Hello all,
> Thanks to your comments, we were able to make a step forward.
> We actually had to use both 'qtcint' and sip to have something
working.
> Here is the piece of code :

>


--

> ----------
> import sys
> import qt
> import ROOT
> import sip
> ROOT.gSystem.Load('qtcint')
>
> class window(qt.QMainWindow):
> def __init__(self):
> # Init the main window.
> qt.QMainWindow.__init__(self)
> self.resize(350, 350)
>
> # Create the central widget.
> self.CentralWidget = qt.QWidget()
> self.setCentralWidget(self.CentralWidget)
> self.Layout = qt.QGridLayout(self.CentralWidget)
>
> # Create a root histogram.
> self.hist = ROOT.TH1F("pipo","pipo", 100, 0, 100)
>
> # Create the main TQtWidget (using sip to get the pointer to the
> central widget).
> self.Address = sip.unwrapinstance(self.CentralWidget)
> self.Canvas =
ROOT.TQtWidget(sip.voidptr(self.Address).ascobject())
> self.Canvas.resize(300, 300)
>
> # Place the TQtWidget in the main grid layout and draw the
histogram.
>
> self.Layout.addWidget(sip.wrapinstance(ROOT.AddressOf(self.Canvas)[0],
> qt.QWidget), 0, 0)
> self.Canvas.show()
> self.Canvas.cd()
> self.hist.Draw()
> self.Canvas.Refresh()
>
> if __name__ == '__main__':
> application = qt.QApplication(sys.argv)
> qt.QObject.connect(application, qt.SIGNAL("lastWindowClosed()"),
> application, qt.SLOT("quit()"))
> w = window()
> w.show()
> application.exec_loop()
> ------------------------------------------------------------------------ --
> ----------
>
> It's almost doing what we want to...meaning, that it's running but
> ultimately the Histogram does not show up on the GUI.
> Notes :
> + If we add the histogram directly to the 'MainWindow' it's working,
> but we obviously need the 'layout' step to work.
>
> We also have these warnings :
> $ python pyqtroot.py
> ** $Id: TGQt.cxx,v 1.35 2006/12/12 20:12:47 brun Exp $ this=0x9fc8d90
> Error in <TUnixSystem::DynamicPathName>: QtGui[.so | .sl | .dl | .a |
> .dll] does not exist in
> $(ROOTSYS)/cint/include:.:/usr/local/root/v5.14.00/lib:/usr/local/root/v 5.
> 14.00/lib:/usr/local/python2.5/lib:/usr/local/lib
> QApplication: There should be max one application object
> Warning in <TClass::TClass>: no dictionary for class Qt is available
> Warning in <TClass::TClass>: no dictionary for class QPaintDevice is
> available
>
> 1) Where does this QtGui library comes from ? (there seems to be one
in
> qt4 but we do not have any in qt3)
> 2) What is creating the 'other' QApplication ? (we instance only one
in
> the main !)
> 3) We're now loading the 'qtcint' dictionnary, so why some Qt class
> dictionaries are still missing ?
>
> Thanks for comments,
> cheers
> Johan
Received on Fri Jan 12 2007 - 19:09:09 CET

This archive was generated by hypermail 2.2.0 : Fri Jan 19 2007 - 05:50:01 CET