[QtRoot] TQtWidget::Refresh() causes segmentation fault

Hi
Thank you very much for you project.
The bad news :frowning: Your short project project has several issues, usage of the zero pointer, double deletion of the died objects , race conditions, incorrect use of the Qt Designer etc. #-o

The good news :bulb: : it is easy to fix :smiley: .

Please, find your fixed project attached. I check it on MS Windows and on CERN LXPLUS as well.
Compare it with your original version. Do not hesitate asking me the further questions. I am willing to elaborate if needed.

The working version of your code looks like this:

[code]#include “MainWindow.h”
#include “ui_MainWindow.h”

MainWindow::MainWindow(QWidget parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
g()
{
ui->setupUi(this);
Int_t x[5], y[5];
for(int i=0; i<5; i++)
{
x[i] = i; y[i]=i
i;
}
g = new TGraph(sizeof(x)/sizeof(float),x,y);
ui->widget->cd();
g->Draw();
}
MainWindow::~MainWindow()
{ }
[/code]

Even though this version does work, it is NOT [-X recommended to use the rendering operation ( including the ROOT methods cd() and Draw() ) from within the widget ctor. The dedicated Qt slot to create the ROOT object is more reliable approach to create the complex Qt widgets.

The new version of the project uses the Qt Designer promote feature to add the “TQtWidget *widget” to UI

(See qt-project.org/doc/qt-4.8/design … ng-widgets for details) .
Qt framework takes care about all widgets it creates. This is why one must not [-o< delete it at all.
The TQtWigdet contains the “embedded” ROOT TCanvas. The later deletes the objects it rendered.
So:

  1. "QMainWindow dtor destroys ui;
  2. ui destroys all children including the TQtWigdet *widget";
  3. TQtWidget::~TQtWidget deletes the embedded TCanvas
  4. TCanvas deletes all objects ( not always though, see ROOT docs for details ) including TGraph

In addition you are recommended to install ( follow to “Complement the existent ROOT installation with QtRoot plugin” qtroot.svn.sourceforge.net/viewv … tExamples/ ) which is the collection of HelloWorld-level working QtRoot applications addressing all QtRoot use cases I have encountered.

Check my recent post HelloCanvas on Qt app using ROOT with VC2010&Qt 4.8.1 also.
RootTry1.0.0.tar.gz (2.21 KB)