0

I'm newbie in C++/Tk and want to pass variable which is defined in C++ to command attribute in button. Herewith I'm posting code snippet.

int eoutputvar ;

stringstream ss ;
string setquery ;

ss.str( "set eoutputvar 10" ) ;
setquery = ss.str() ;

entry(".eoutput") -textvariable(eoutputvar) -width(20) ;

button(".b1") -text("click it") -command( setquery );
pack(".eoutput" ) -side("left") ;

My objective here is to set eoutputvar of entry widget when the button is clicked.

Rony Rozen
  • 3,957
  • 4
  • 24
  • 46
jayvyas13
  • 1
  • 1

1 Answers1

0

You have to declare your variables as extern "C".

extern "C" {
  int eoutputvar;
  char *setquery;
}

The setquery parameter also needs to be a "C" variable and can't be declared as a string. So as in this answer:

setquery = ss.c_str();
Community
  • 1
  • 1
Brad Lanam
  • 5,192
  • 2
  • 19
  • 29
  • No, its just not working yet. I've also tried namespace declaration. – jayvyas13 Aug 28 '15 at 04:57
  • Sorry, missed the changes needed for `setquery`. All variables that get passed to the Tcl/Tk routines will need to have "C" linkage. – Brad Lanam Aug 28 '15 at 15:55
  • thanks for giving your inputs. But, this fix is also not working as it says: c_str is not a member of stringstream. it will be great help if you can provide a solution for this as I'm googling for it from many days. – jayvyas13 Aug 31 '15 at 05:21