RE: PyQt and PyROOT

From: Fine, Valeri <fine_at_bnl.gov>
Date: Thu, 11 Jan 2007 21:27:33 -0500


Hello Johan,
I am begging the pardon for the "sliced" response.

> after some more investigation I am convinced the problem comes from
this
> line

  Your explanation of the problem is not correct, sorry.

> > Warning in <TClass::TClass>: no dictionary for class QWidget is
> available
> from python just doing 'from ROOT import TQtWidget' gives this
warning.

The message above is provided by ROOT rather by Python. It is the "warning". It should cause no problem unless one wants to create an instance of the very QWidget class from the ROOT prompt. However there is no obstacle to create the TQtWidget instance with the default constructor (This is what we really want to do)

> looking into the TQtWidget source files, one can see that this classed
> is built on QWidget.
> so when trying to access this class with python, PyROOT tries to look
> for the QWidget class and does not find any information on it ('no
> dictionnary') because Qt is only a module of ROOT.

No, it is not correct. The problem comes from another place. Problem is not cause by the base class of TQtWidget as you suggested. The problem is caused by first parameter of that class constructor.

Pay your attention, the first parameter of the TQtWidget ctor is the pointer to QWidget.

Now, see the trouble statement again:

> >> self.Canvas = TQtWidget(self.CentralWidget)

I believe there is no problem to create the TQtWidget via ctor, but . . . there is the problem to PASS the pointer of the PyQT created CentralWidget object to the TQtWidget ctor as its first parameter.

By some reason, PyQt is not aware that the type of the first parameter of the TQtWidget and type of the CentralWidget object are the same. THIS IS THE PROBLEM. I believe some Python guru can quickly explain us what should be done if any. I can not, sorry.

> The solution is as you say to build a dictionnary for the Qt classes,

I do not think (I have to repeat) this may have helped. The PyQt is already has the QWidget definition. Bringing in the second one should lead to some sort of the clash between two different definitions of one and the same class, namely QWidget.

In fact as soon as you load qtcint you do not need any PyQt at all. It should work (well, in theory only. It can be done but ... nobody tried that yet ;)

> One hope would be to have PyROOT knowing about QWidget directly via
> PyQt, but I am not sure that's possible...

As soon as qtcint is loaded, PyROOT should "know" about QWidget and ... no PyQt is needed at all. But, see my remark above, nobody has tried that yet ;)

> Comments are still welcome :o)

 Try to

  1. build the qtcint (say "make qtcint" from $ROOTSYS)
  2. activate QtRoot plugin via ".rootrc" file (How? See "ROOT Manual")
  3. Start PyROOT. ( No PyQt !!!)
  4. Try to execute the ROOT macro from $ROOTSYS/tutorials/gui/QtFileDialog.C from your Python.

 let me know the outcome.

Best regards, Valeri

> cheers,
> Johan Bregeon
>
> --------- some more information ---------
> http://root.cern.ch/root/Version511.news.html
> The Qtcint interface:
> CINT has a new build option to generate the dictionary for the Qt
> classes. This dictionary is not built by default in the binary
> distribution files because the resulting library is quite large (>2
> Mbytes).
>
> and
> root/cint/lib/qt/README.txt
> This directory includes build environment for Qt library access DLL.
Run
> 'sh setup' to build 'include/qtcint.dll'. You need to modify
setup.bat
> script for setting Qt directory in your system. By default, c:\qt is
set.
> Basic Qt library can be used in an interpreted code by including
> <qtcint.dll>
> Platform support:
> Windows Visual C++ 6.0
> qtcint.dll hasn't been port to Linux/UNIX platforms. Your
> contribution will be highly appreciated.
> -----------------------------------------------------
>
>
> Fine, Valeri wrote:
> > Hello Luca,
> >
> >
> >> Hi Valeri,
> >> I apologize for not writing on the root talk forum, but I just
> >> registered and it seems like
> >>
> >
> > I am forwarding your message to the ROOTTalk and RootDev lists
> >
> > I am not fluent with Python, sorry. Probably you (or some one from
the
> > roottalk) will need to explain me some basic things about Python and
> > Python ROOT.
> >
> > From the first glance your trouble is not caused by QtRoot class
like
> > TQtWidget rather by the "pure" Qt class which is QWidget.
> >
> > By this reason my first question is, "Does your code work if you
remove
> > the line
> >
> >
> >> self.Canvas = TQtWidget(self.CentralWidget)
> >>
> > and replace it with the "pure" Qt class like
> >
> > self.Canvas = QWidget(self.CentralWidget);
> > ?
> >
> > My guess it does work. I did pay an attention to the line
> >
> >
> >> self.CentralWidget = QWidget()
> >>
> >
> > that your python did not complain about.
> >
> > I did see the Python is aware about TQtWidget as well. However it
is
> > confused with the ctor parameter QWidget.
> > I do not know how one can "explain" python that this parameter is
very
> > pointer to the QWidget class the python is aware about via
> >
> >
> >> from qt import *
> >>
> >
> > I.e. I did see some confusion with the different dictionaries
however my
> > knowledge is not enough to pinpoint the reason.
> >
> > May be the only thing you need to do is to build the "qtcint"
RootCint
> > dictionary for the Qt classes
> > http://root.bnl.gov/QtRoot/htmldoc/src/qtclasses.h.html. However, I
am
> > not sure whether it makes sense for you. It may add the insult to
injury
> > ;)
> >
> > I hope some Python people on list can clarify the issue.
> >
> > Best Regards
> > Valeri Fine
> > ---------------
> > Brookhaven National Laboratory
> > Upton, NY 11973, USA
> > Phone: +1 631 344 7806
> > Fax: +1 631 344 4206
> > E-mail: fine_at_bnl.gov
> >
> >
> >> -----Original Message-----
> >> From: Luca Baldini [mailto:luca.baldini_at_pi.infn.it]
> >> Sent: Thursday, January 11, 2007 10:32 AM
> >> To: Fine, Valeri
> >> Cc: johan.bregeon_at_pi.infn.it
> >> Subject: PyQt and PyROOT
> >>
> >> Hi Valeri,
> >> I apologize for not writing on the root talk forum, but I just
> >> registered and it seems like
> >> it takes some time for my account to be activated.
> >> We are trying to put a ROOT canvas on a qt gui and we would like to
be
> >> able to do that from
> >> python with pyROOT and pyQt (ROOT 5.14.00, qt 3.3.3, pyQt 3.17,
python
> >> 2.5).
> >> Based on the c++ examples, we tried the following
> >>
> >> import sys
> >> from qt import *
> >> from ROOT import *
> >>
> >> class window(QMainWindow):
> >> def __init__(self):
> >> QMainWindow.__init__(self)
> >> self.CentralWidget = QWidget()
> >> self.setCentralWidget(self.CentralWidget)
> >> self.Layout = QGridLayout(self.CentralWidget)
> >> self.Canvas = TQtWidget(self.CentralWidget)
> >> self.Layout.addWidget(self.Canvas, 0, 0)
> >>
> >>
> >> if __name__ == '__main__':
> >> application = QApplication(sys.argv)
> >> w = window()
> >> w.show()
> >> application.exec_loop()
> >>
> >>
> >> but it doesn't work:
> >>
> >> Warning in <TClass::TClass>: no dictionary for class QWidget is
> >>
> > available
> >
> >> Traceback (most recent call last):
> >> File "window.py", line 18, in <module>
> >> w = window()
> >> File "window.py", line 12, in __init__
> >> self.Canvas = TQtWidget(self.CentralWidget)
> >> TypeError: TQtWidget::TQtWidget(QWidget* parent = 0) =>
> >> could not convert argument 1
> >>
> >>
> >> Any suggestion you can give me?
> >>
> >> Thanks a lot,
> >> Luca Baldini, INFN Pisa
> >>
Received on Fri Jan 12 2007 - 03:28:06 CET

This archive was generated by hypermail 2.2.0 : Fri Jan 12 2007 - 11:50:01 CET