Problem with GUI

Hi,

I am trying to make a GUI - basically two number entries and a button. When the button is pressed, the values of the number entries are acquired and then passed around as global integer variables.
However, I am struggling to make the code work - always end up with segmentation violation.
Please, have a look and tell me what do I do wrong.
example_ex.cpp (5.11 KB)

Hi,

You are redefining the TGNumberEntry class members:
First definition:

private: 
  TGNumberEntry       *neDateSt, *neDateEn; 

Second definition:

  //Create Date Start button
  TGNumberEntry *neDateSt = new TGNumberEntry(fDates, 1, 8, 11, 
                                              TGNumberFormat::kNESInteger,
                                              TGNumberFormat::kNEANonNegative, 
                                              TGNumberFormat::kNELLimitMinMax,
                                              0, 100);
  fDates->AddFrame(neDateSt, new TGLayoutHints(kLHintsLeft,5,5,3,3));
  neDateSt->Connect("ValueSet(Long_t)", "MyMainFrame", this, "DoSetValue1()");
  
  
  //Create Date End button
  TGNumberEntry *neDateEn = new TGNumberEntry(fDates, 20, 8, 21, 
                                              TGNumberFormat::kNESInteger,
                                              TGNumberFormat::kNEANonNegative, 
                                              TGNumberFormat::kNELLimitMinMax,
                                              0, 100);

To solve the problem, just remove the “TGNumberEntry *” in the constructor, as shown below:

  //Create Date Start button
  neDateSt = new TGNumberEntry(fDates, 1, 8, 11, 
                               TGNumberFormat::kNESInteger,
                               TGNumberFormat::kNEANonNegative, 
                               TGNumberFormat::kNELLimitMinMax,
                               0, 100);
  fDates->AddFrame(neDateSt, new TGLayoutHints(kLHintsLeft,5,5,3,3));
  neDateSt->Connect("ValueSet(Long_t)", "MyMainFrame", this, "DoSetValue1()");
  
  
  //Create Date End button
  neDateEn = new TGNumberEntry(fDates, 20, 8, 21, 
                               TGNumberFormat::kNESInteger,
                               TGNumberFormat::kNEANonNegative, 
                               TGNumberFormat::kNELLimitMinMax,
                               0, 100);

Cheers, Bertrand.

That worked perfectly!

Thanks a lot for the prompt reply!

You’re welcome!
Cheers, Bertrand.