Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 08-05-2012, 08:18 AM   #1
LQ Newbie
Registered: Aug 2012
Posts: 4

Rep: Reputation: Disabled
Exclamation GTK+3 - Gtk Entry - Seg Fault? - Please help! :S


I am writing a program in C++ which creates a GTK Window and should get input from the user. (But it's not working!)

The line which is causing the problem is:
textP = gtk_entry_get_text(GTK_ENTRY(entry_name));
textP is a tempoary variable which I created for debugging.
The terminal output looks like this:
Segmentation fault (core dumped)

Process returned 139 (0x8B) execution time : 2.252 s
Press ENTER to continue.
(I am working in Code::Blocks or with g++ command line.)

Other relevent pieces of code:
GtkEntryBuffer *entry_name_buffer; // Entry buffer for user input
const gchar* textP; // The string to hold the entry text
GtkWidget *entry_name; // The entry widget which will hold the persons name

entry_name_buffer = gtk_entry_buffer_new(NULL, 0); 
entry_name = gtk_entry_new_with_buffer(entry_name_buffer);
And I want to be able to do something like:

std::string any_old_string = gtk_entry_get_text(GTK_ENTRY(entry_name));

A button calls a function which is supposed to transfer the text in the gtk entry (textbox thing) to a string which can be used elsewhere in my program.

Please help!

Thanks, Edward Bird.

Last edited by PlunderingPirate; 08-05-2012 at 08:25 AM.
Old 08-05-2012, 10:08 AM   #2
LQ Newbie
Registered: Aug 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
Talking Callback Functions must be static?

Ah, I think I have found the problem.

Apparently all callback functions have to be static.
Solution: Make callback functions static.

New Problem:
Apparently static functions cannot access/modify any NON-STATIC data.
Solution: Declare all required data as static, and declare static data members ABOVE main for use.

All problems fixed!

To do these things: (examples)
   Put "static" infront of callback functions.
   Change "bool boolean_member_name" To "static bool boolean_member_name"
   Put "bool boolean_member_name" OR "bool class_name::boolean_member_name" above int main(...)


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Where does the gtk.entry command save the text entered by the user? adhm9009 Linux - Newbie 4 07-27-2012 07:35 AM
[SOLVED] Python: Placing a gtk.Entry() into a Toolbar MetaMan Programming 2 06-18-2011 03:34 PM
Get input from entry using Gtk? michaelinux Programming 3 05-12-2011 02:16 PM
GTK entry nAvi Programming 2 08-16-2003 10:59 AM
segmentation fault with my Gtk Application jaganmolleti Programming 1 03-18-2003 11:05 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:07 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration