# TApplication::Run() stucks the terminal

**URL:** <https://root-forum.cern.ch/t/tapplication-run-stucks-the-terminal/41892>\
**Category:** Newbie\
**Created:** [October 17, 2020, 9:15pm UTC](https://root-forum.cern.ch/t/tapplication-run-stucks-the-terminal/41892 "2020-10-17T21:15:26Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![dsubhro](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dsubhro/32/24279_2.png) [@dsubhro](https://root-forum.cern.ch/u/dsubhro)\
**Post date:** [October 17, 2020, 9:15pm UTC](https://root-forum.cern.ch/t/tapplication-run-stucks-the-terminal/41892/1 "2020-10-17T21:15:26Z")

</div>

ROOT Version: 6.22  
\_Platform: ubuntu  
\_Compiler: g++

Hi,  
I have a code in c++ where I use TApplication to stop terminating the program before the graph Shows.  
the code:

```auto
#include <iostream>
#include "TF1.h"
#include "TApplication.h"
using namespace std;
int main()
{
    TApplication app("app", nullptr, nullptr);
    TF1 *f1 = new TF1("f1","sin(x)", -5, 5);
    f1->SetLineColor(kBlue+1);
    f1->SetTitle("My graph; x");
    f1->Draw();
    app.Run();
    return 0;
}

```

It perfectly runs, but the terminal stucks before the program returns 0  
How could I solve this??  
Thank you,  
Regards.

---

<div class="post-metadata">

**Author:** ![etejedor](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/e/e79b87/32.png) [@etejedor](https://root-forum.cern.ch/u/etejedor)\
**Post date:** [October 19, 2020, 7:44am UTC](https://root-forum.cern.ch/t/tapplication-run-stucks-the-terminal/41892/2 "2020-10-19T07:44:45Z")

</div>

Hello,

Is your goal to plot the function and inspect it interactively? If that’s the case, it might be better that you draw your function from the ROOT prompt.

```auto
$ root
root [0] TF1 *f1 = new TF1("f1","sin(x)", -5, 5);
root [1] f1->SetLineColor(kBlue+1);
root [2] f1->SetTitle("My graph; x");
root [3] f1->Draw();

```

---

<div class="post-metadata">

**Author:** ![yus](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/9fc348/32.png) [@yus](https://root-forum.cern.ch/u/yus)\
**Post date:** [October 19, 2020, 11:14am UTC](https://root-forum.cern.ch/t/tapplication-run-stucks-the-terminal/41892/3 "2020-10-19T11:14:13Z")

</div>

Also, if a compiled version is a requirement for you, you could do the following:

```auto
#include "TF1.h"
#include "TApplication.h"
#include "TCanvas.h"
using namespace std;
int main()
{
        TApplication app("app", nullptr, nullptr);
        TCanvas* c = new TCanvas("c", "Something", 0, 0, 800, 600);
        TF1 *f1 = new TF1("f1","sin(x)", -5, 5);
        f1->SetLineColor(kBlue+1);
        f1->SetTitle("My graph; x");
        f1->Draw();
        c->Modified(); c->Update();
        printf("Type any digit and hit `Enter` to exit: "); Int_t a; std::cin>>a;
        return 0;
}

```

---

<div class="post-metadata">

**Author:** ![dsubhro](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dsubhro/32/24279_2.png) [@dsubhro](https://root-forum.cern.ch/u/dsubhro)\
**Post date:** [October 20, 2020, 4:21am UTC](https://root-forum.cern.ch/t/tapplication-run-stucks-the-terminal/41892/5 "2020-10-20T04:21:47Z")

</div>

Sir, I require to run the program by g++ compiler

---

<div class="post-metadata">

**Author:** ![dsubhro](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dsubhro/32/24279_2.png) [@dsubhro](https://root-forum.cern.ch/u/dsubhro)\
**Post date:** [October 20, 2020, 4:22am UTC](https://root-forum.cern.ch/t/tapplication-run-stucks-the-terminal/41892/6 "2020-10-20T04:22:58Z")

</div>

Hello, sir basically you are holding the program by putting input request. Yes I can use that. But is there any other way to hold the program on untill I close the graph canvas, using TApplocation??  
By the way thank you sir, it works.

---

<div class="post-metadata">

**Author:** ![etejedor](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/e/e79b87/32.png) [@etejedor](https://root-forum.cern.ch/u/etejedor)\
**Post date:** [October 20, 2020, 6:47am UTC](https://root-forum.cern.ch/t/tapplication-run-stucks-the-terminal/41892/7 "2020-10-20T06:47:56Z")

</div>

Perhaps @bellenot or @couet know?

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [October 20, 2020, 7:03am UTC](https://root-forum.cern.ch/t/tapplication-run-stucks-the-terminal/41892/8 "2020-10-20T07:03:15Z")

</div>

If you want to quit the application when closing the canvas:

```auto
#include <iostream>
#include "TF1.h"
#include "TApplication.h"
#include "TCanvas.h"
#include "TRootCanvas.h"

int main()
{
    TApplication app("app", nullptr, nullptr);
    TCanvas* c = new TCanvas("c", "Something", 0, 0, 800, 600);
    TF1 *f1 = new TF1("f1","sin(x)", -5, 5);
    f1->SetLineColor(kBlue+1);
    f1->SetTitle("My graph; x");
    f1->Draw();
    c->Modified(); c->Update();
    TRootCanvas *rc = (TRootCanvas *)c->GetCanvasImp();
    rc->Connect("CloseWindow()", "TApplication", gApplication, "Terminate()");
    app.Run();
    return 0;
}

```

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [October 20, 2020, 7:16am UTC](https://root-forum.cern.ch/t/tapplication-run-stucks-the-terminal/41892/9 "2020-10-20T07:16:47Z")

</div>

And if you just want the ROOT prompt:

```auto
#include <iostream>
#include "TF1.h"
#include "TRint.h"
#include "TCanvas.h"

int main()
{
    TRint app("app", nullptr, nullptr);
    TCanvas* c = new TCanvas("c", "Something", 0, 0, 800, 600);
    TF1 *f1 = new TF1("f1","sin(x)", -5, 5);
    f1->SetLineColor(kBlue+1);
    f1->SetTitle("My graph; x");
    f1->Draw();
    c->Modified(); c->Update();
    app.Run();
    return 0;
}

```
