Textentry and textbutton

Hi

I have in my program a textentry, where you can put the name of the file to analyse, then when you push enter the program makes a plot.

But as I can see pushing enter is not intuitive for user, so I would like to put just by the TextEntry a TextButton like “Make a plot” with the same function as pressing enter. But then I get segmentation fault. What is wrong?

This is the code:

[code]
map1=new TGTextEntry(mframe,“Map00002009_000000_P1m.txt”,-1);
map1->Connect(“ReturnPressed()”,“MyMainFrame”,this,“SetMap1()”);

mframe->AddFrame(map1, new TGLayoutHints(kLHintsCenterX,BL,1,BU,BD));

TGTextButton *lm1 = new TGTextButton(mframe,"&load new \n map 1");
lm1->Connect(lm1,“Clicked()”,“MyMainFrame”,this,“SetMap1()”);
mframe->AddFrame(lm1, new TGLayoutHints(kLHintsCenterX,BL,BR,BU,BD));[/code]

What I can add is that SetMap1 takes text from ‘map1’ TextEntry.

Hi,

It is hard to guess what’s going wrong with your code with so little information… Could you post a more complete part of your code (especially the slot method SetMap1()) or a working macro showing the problem?

Cheers, Bertrand.

Here is it:

[code]void MyMainFrame::SetMap1()
{
charbuff=new char [30];
sprintf(buff,"%s",const_cast<char
>(map1->GetText()));

if(targc[1]) delete SomeMap1;
fMain->SetCleanup(kDeepCleanup);
fMain->Cleanup();
fMain->DeleteWindow();
targc[1]=1;

FILE *plik;

if(!(plik=fopen(buff,"r"))){
char pre[30]="scp usr1@ps1111:2009/";
char command[60];
	sprintf(command,"%s%s %s",pre,buff,buff);
system(command);
}
else fclose(plik);

MakeGUI(buff,SomeMap2->title,SomeMap3->title,1); }
[/code]

where TextEntry map1 is a component of a class MyMainFrame
when I do not use button,only TextEntry, everything works

Hi,

You must not call destructor of the signal emitter in the slot.
This code:

fMain->Cleanup(); fMain->DeleteWindow();
Destroys the text entry and the button (and all other GUI elements)… It may work in some cases (e.g. the text entry), but will lead to a crash most of the time…

Cheers,
Bertrand.