Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

(gtk+) button with integer as its label

35 views
Skip to first unread message

stinkinrich88

unread,
Jun 2, 2007, 8:38:50 AM6/2/07
to
Hello!

I'm really new to c++. I've been doing java for a while though.

I'm using linux so I wanted to make a gtk+ gui application. I want to
make a simple calculator to help me learn, so, say I want three
buttons with labels "1", "2" and "3", how can I change the following
code to work:

GtkWidget *button;

int i;
for (i = 0; i<3; i++);
{
button = gtk_button_new_with_label (i);
g_signal_connect (G_OBJECT (button), "clicked",
G_CALLBACK
(callback), (gpointer) "button 2");
gtk_table_attach_defaults (GTK_TABLE (table), button,
i, (i+1), 1,
2);
gtk_widget_show (button);
}

at the moment it doesn't like gtk_button_new_with_label (i) because I
is an integer and it wants a "const gchar*" apparently.

thanks!

jahhaj

unread,
Jun 2, 2007, 8:43:05 AM6/2/07
to

See my reply in comp.lang.c++

john

Roger Leigh

unread,
Jun 3, 2007, 5:19:59 PM6/3/07
to
stinkinrich88 <stinki...@googlemail.com> writes:

> I'm really new to c++. I've been doing java for a while though.
>
> I'm using linux so I wanted to make a gtk+ gui application. I want to
> make a simple calculator to help me learn, so, say I want three
> buttons with labels "1", "2" and "3", how can I change the following
> code to work:

Have a look at std::ostringstream (trivial example):

#include <iostream>
#include <sstream>

int
main ()
{

for (unsigned int i = 0; i < 10; ++i)
{
std::ostringstream os;
os << i;

std::cout << i << ": " << os.str() << "\n";
}

return 0;
}

A stringstream puts the output into a string rather than to an fstream
or whatever ostream you normally use. You can use it exactly like
std::cout and other stream types, but the str() method will give you
the output back as a stream.

Also, if you are using C++, take a look at Gtkmm. It's a lot nicer
than the GTK+ C interface.


Regards,
Roger

--
.''`. Roger Leigh
: :' : Debian GNU/Linux http://people.debian.org/~rleigh/
`. `' Printing on GNU/Linux? http://gutenprint.sourceforge.net/
`- GPG Public Key: 0x25BFB848 Please GPG sign your mail.

0 new messages