I am working on trying to get Text input from my text entry fields to an array. I have 8 text entry fields and have been following many of the tutorials. So far from what I gathered . I have
void on_Save_and_Process_button_clicked(GTKButton *button, GtkEntry *text){
GTKWidget *entry1 = lookup_widget(text,"entry1");
Const g char *entry_text1 = gtk_entry _get_text(GTK_ENTRY(entry1));
}
I am getting an warning in:
GTKWidget *entry1 = lookup_widget(text,"entry1");
That says:
warning: intialization make pointer from integer without a cast
This my first GTK project. Any help,guidance, links to tutorials of similar projects would be much appreciated.
The function lookup_widget was part of Glade 2, a long time ago. Back then, Glade would generate C code, instead of an XML file, and that function was included in the generated code.
You can't even run Glade 2 anymore most likely, so the tutorial you are using is not going to help you very much. Use a more modern tutorial, such as the one included in the official GTK 3.x documentation.
Related
As seen in the Gtk documentation here there is a method to set the visual of the Widget which seems to be missing from gtkmm (C++ wrapper).
While trying to port a Gtk application from C to C++ using gtkmm-3.0, quickly discovered that the set_visual() method is missing. Although there is a get_visual() that returns the visual of the widget.
The C code looks like this:
GdkScreen *screen = gtk_widget_get_screen(widget);
GdkVisual *visual = gdk_screen_get_rgba_visual(screen);
if (visual == NULL)
visual = gdk_screen_get_system_visual(screen);
gtk_widget_set_visual(widget, visual);
Does anyone know how can i set the widget visual with a custom one?
If the C++ wrapper does not provide what you need, you can always get a pointer to the underlying C GObject instance and work with it as you would in a typical GTK C application. Check out this method for Gtk::Widget:
GtkWidget* Gtk::Widget::gobj()
So you can call this on your widget, get a C GtkWidget pointer and call gtk_widget_set_visual on it like you are doing in your question. Note that this solution works all across Gtkmm, which in my opinion is a really nice feature that other wrappers do not have.
I am posting this question because I have a problem with my beginner programming project.
I am new in the use of gtk and I am blocked by a problem that I wish to expose to you.
For my program to work I need to clear my store list and rewrite it, but when I run my gtk_list_store_clear(store) function my compiler displays an error of this type.
enter image description here
void actualize_index_of_rep()
{
int i;
GtkTreeIter iter;
for(i=0;i<rep_size;i++)
myRep[i].index=i;
gtk_list_store_clear(store);
for(i=0;i<rep_size;i++)
{
gtk_list_store_append(store,&iter);
gtk_list_store_set(store,&iter,0,myRep[i].name,1,myRep[i].tel,2,myRep[i].index,-1);
}
return;
}
For people who want the entire code he is here
enter link description here
And the save file
enter link description here
Thank you in advance for your time :)
I pulled down a copy of your program, built it, and ran it. I encountered the same issue. To be brief, after adding in some "g_printf" statements to track the process, I discovered that you had two functions called when a row is selected and the deletion button is clicked.
remove_from_prog();
remove_from_list();
When I scanned through the first function, I saw that it was saving a copy of the list out to your "save.data" file, omitting the selection that was deleted. The function then rebuilds the list and view. So, when the second function is called ("remove_from_list"), it can no longer find the row selection which then throws the error you see. The bottom line is that it appears that you do not even need the "remove_from_list" function.
Hope that helps.
Regards.
I made a GUI in Glade. I have this kind of structure:
_ A GtkWindow named winTimer
__ A GtkVBox
___ A GtkHBox
____ A GtkAlignment called alignTimer with absolutely nothing inside.
My structure (gif)
I do:
controlli->alignTimer=GTK_WIDGET(gtk_builder_get_object(builder,"alignTimer"));
controlli->pbTimerComposito = gdk_pixbuf_new(GDK_COLORSPACE_RGB,0,8,320,200);
controlli->imgTimer = GTK_WIDGET(gtk_image_new_from_pixbuf(controlli->pbTimerComposito));
gtk_container_add(GTK_CONTAINER(controlli->alignTimer),controlli->imgTimer); /* warning */
gtk_widget_show(controlli->imgTimer);
Where controlli is a pointer to a struct that has, among other things:
GtkWidget *alignTimer;
GdkPixbuf *pbTimerComposito;
GtkWidget *imgTimer;
I get this at runtime:
Gtk-WARNING **: Attempting to add a widget with type GtkImage to a GtkAlignment, but as a GtkBin subclass a GtkAlignment can only contain one widget at a time; it already contains
a widget of type GtkImage
But that is not true! It's the first and only widget that I'm adding! What's happening? I had done the exact same thing in another part of my app and it's been working perfectly for years.
My environment:
- Windows XP SP3
- MinGW
- GCC 4.8.1
- GTK 2.24.10
PS I know I'm using an old version of GTK, deprecated widgets and an ancient OS, but I code just for fun so I'm OK with that. Any help will be very appreciated.
Problem solved (or, rather, there was no problem).
The function that contained the code I posted above was called twice. Facepalm for myself.
I’m in love with IUP! However I cannot figure out how to get programmatic access (in C) to GUI elements in a dialog loaded by IupLoad() from a LED file.
One extremely laborious way would be to edit the LED file so as to manually give handle names to each single GUI element, then manually define corresponding variables for each element in C, then manually load handles into each variable by using IupGetHandle().
One comfortable way to do it would be to convert the LED file to a C header file using the built-in Layout Dialog tool. The resulting code makes each element available to the application in a simple array called Ihandle* containers[]. But this way deprives us of the benefits of LED files, such as the ability to edit GUI of a binary application by the user and keeping the C code small.
Is there no good way to do it?
Do I overrate the benefits of a third way, if it existed?
I cannot find any IupLoad() example in the directory with C examples.
My own example below explicitly defines one handle name for the top element (dialog) only. It features a very simple dialog where defining each element manually wouldn’t be a hard work at all. But this is only a test example for Stack Overflow and my question is relevant to complex dialogs.
C file:
#include <stdlib.h>
#include <iup.h>
int main(int argc, char **argv)
{
IupSetGlobal("UTF8MODE", "YES");
// IupSetGlobal("UTF8MODE_FILE", "YES");
IupOpen(&argc, &argv);
if(IupLoad("dropdown.led")) IupMessage("Error", "Failed to load LED.");
else {
Ihandle *dropdown = IupGetHandle("dropdown");
IupShow(dropdown);
IupMainLoop();
}
IupClose();
return EXIT_SUCCESS;
}
Corresponding dropdown.led file:
dropdown = DIALOG[TITLE=dropdown.led](
HBOX[CMARGIN=10x10,CGAP=10](
LIST[VALUE=3, 1=я, 2=ты, 3=оно, 4=мы, 5=вы, 6=они, DROPDOWN=YES](do_nothing),
LIST[VALUE=3, 1=ik, 2=je, 3=hij, 4=we, DROPDOWN=YES](do_nothing)
)
)
Which brings us to another question: how can I make Russian characters visible? But this issue is owed a separate thread which I will accordingly create.
All questions that pertain to this particular example:
How do I get access to GUI elements in a IUP dialog loaded from a LED file? (current)
How can I make Russian letters visible in a IUP dialog loaded from a LED file?
A gap in IUP dropdown lists
The way os to use IupGetHandle to get access to some element then use IupGetChild*, GetBrother, GetParent functions to get the element you want.
Another option is to use the NAME attribute. You set it on the element you want then use IupGetDialogChild to retrieve the element given the NAME value.
I am trying to compile and run an example of gtk+3, unfortunately, the example is from gtk+2 manual, I can't find anything useful on gtk+3 and I can't download gtk+2.
On the example there are a couple of function like this:
void entry_toggle_editable( GtkWidget *checkbutton,
GtkWidget *entry )
{
gtk_editable_set_editable(GTK_EDITABLE(entry),GTK_TOGGLE_BUTTON(checkbutton)->active);
}
When compiling I got this error:
'GtkToggleButton {aka struct _GtkToggleButton}' has no member named 'active'
I looked in all manuals. I was able to find in order to get around the problem, I understand that probably it is a release compatibility problem, but gtk+3 manuals are really useless for somebody approaching for the first time Gtk.
One of the biggest changes between GTK+ 2 and GTK+ 3 is that GTK+ 3 gets rid of all public structure fields, replacing them with GObject properties. So instead of saying
GTK_TOGGLE_BUTTON(checkbutton)->active
you say
gboolean active;
g_object_get(checkbutton, "active", &active, NULL);
(The NULL is because g_object_get() can get multiple properties from the same object at the same time; the NULL says "that is all I need from this call".)
GTK+ also provides accessor methods to add type checking, so you can also say
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkbutton))
Using these when available is preferable to calling g_object_get() directly.
The GTK+ documentation does come with a tutorial. As you probably realized, you cannot use GTK+ 2 examples to learn GTK+ 3 without modification; you will need to spend more time finding GTK+ 3 examples.