TCanvas in a ROOT Based Qt Application

Hello to all.

I am trying to design a Qt Application for a DAQ System and I would like to have a TCanvas/TRootEmbeddedCanvas in my project using ROOT as plotter for my online display.
Imagine that my mainwindow consists of a QTabWidget, and a tab of this is called displayTab. What I would like to do is to import a TCanvas in this tab. During my testing phase, what I’m trying to achieve is when a QPushButton is clicked(), just draw a TF1 in a canvas which has as parent the displayTab.

So far, I have edited my .pro file to include these lines

[code][…]
include("$(ROOTSYS)/include/rootcint.pri")
[…]
win32:CONFIG(release, debug|release): LIBS += -L/home/nick/root/lib/release/ -lGpad -lCint -lCore -lGraf -lGraf3d -lHist -lGui -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lRIO -lNet -lThread -lGQt
else:win32:CONFIG(debug, debug|release): LIBS += -L/home/nick/root/lib/debug/ -lGpad -lCint -lCore -lGraf -lGraf3d -lHist -lGui -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lRIO -lNet -lThread -lGQt
else:symbian: LIBS += -lGpad -lCint -lCore -lGraf -lGraf3d -lHist -lGui -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lRIO -lNet -lThread -lGQt
else:unix: LIBS += -L/home/nick/root/lib/ -lGpad -lCint -lCore -lGraf -lGraf3d -lHist -lGui -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lRIO -lNet -lThread -lGQt

INCLUDEPATH += /home/nick/root/include
DEPENDPATH += /home/nick/root/include[/code]

With these lines I can link the ROOT libraries and they seem to work, as for example I use a TEnv class instance and works like a charm.
I include TQtWidget.h header in the class that is going to draw the function and the diplay() function that is going to be called when the QPushButton is clicked() looks like this

void Classs::display(){
TQtWidget *tqt = new TQtWidget(m_ui->displayTab);   // trying to convert a QWidget to TQtWidget
TCanvas *c1 = new TCanvas(tqt);    // to my knowledge this should place a TCanvas to tqt (a.k.a. displayTab)
c1->cd();
TF1 *f1 = new TF1("f1", "1/x", 0,10);
f1->Draw();
}

It compiles, links and builds perfectly but during execution when the QPushButton is clicked a new TCanvas pops up with the function plotted. #-o
I also tried using TRootEmbeddedCanvas, but as its constructor asks for a TGWindow parent, I could not create one and bind it to the displayTab. Finally, the solution of promotion of the QWidget to TQtWidget (or even TGWindow) didn’t work, as I’m using QtCreator and an error comes up concerning its built-in header file

../../root/include/TGWindow.h: In member function ‘void Ui_Interface::setupUi(QMainWindow*)’: ../../root/include/TGWindow.h:49:4: error: ‘TGWindow::TGWindow(Window_t)’ is protected ui_interface.h:170:47: error: within this context ui_interface.h:170:47: error: invalid conversion from ‘QWidget*’ to ‘Window_t’ ui_interface.h:170:47: error: initializing argument 1 of ‘TGWindow::TGWindow(Window_t)’ ui_interface.h:171:23: error: ‘class TGWindow’ has no member named ‘setObjectName’ ui_interface.h:172:23: error: ‘class TGWindow’ has no member named ‘setGeometry’

Is there any way to bind the canvas to the main window? :blush:

I would like to thank you in advance for any input you could provide me with.

P.S. I’m using ROOT 5.30, Qt 4.7.2 and I’m under UNIX environment.

Hi,

I’m not a Qt expert, but here is a very simple example I have since quite a long time (just had to update it for Qt4). Just take a look and see if it can help you

Cheers, Bertrand.
simple_canvas.tar.gz (2.19 KB)

[quote=“estelion”]…
I include TQtWidget.h header in the class that is going to draw the function and the diplay() function that is going
P.S. I’m using ROOT 5.30, Qt 4.7.2 and I’m under UNIX environment… [/quote]

Please, download the BNL version qtroot.svn.sourceforge.net/viewv … tExamples/ (BNL SVN repository is not available from outside of the BNL :slight_smile:

I think the QRootShower which is the Qt-ed version of the Bertrand’s RootShower application does meet your use case.
qtroot.svn.sourceforge.net/viewv … RootShower
I am begging a pardon, I’ve realized I missed ](*,) your post made on Thu Aug 18, 2011 3:41