Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 885003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:50:17+00:00 2026-05-15T12:50:17+00:00

I need in global list in my gtk+ application, i use for it GList:

  • 0

I need in global list in my gtk+ application, i use for it GList:

For example:

I have structure:

typedef struct _data
{
  Glist list;
}Data;

I want to use one copy of the list in the whole program:

I have a function bulid my list:

gboolean build_list()
{
   Data->list = g_list_append(Data->list, "First ");
   Data->list = g_list_append(Data->list, "Second ");
   Data->list = g_list_append(Data->list, "Third ");

   g_list_foreach(Data->list, (GFunc)printf, NULL);
}

After calling this function to display all items from the list:

First Second Third

,but when i try to make it in another function – for example:

void foreach()
{   
    g_list_foreach(Data->list, (GFunc)printf, NULL);
}

I see error in gdb:

**Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xb7335700 (LWP 5364)]
0xb765a7d7 in strchrnul () from /lib/i686/cmov/libc.so.6
**

How can i create global list in my application?

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T12:50:17+00:00Added an answer on May 15, 2026 at 12:50 pm
    typedef struct _data
    {
      Glist list;
    } Data;
    

    That makes Data a type (i.e. you can define a variable of type Data by doing `Data data_var;), but in your code you are using it as a variable:

    gboolean build_list()
    {
       Data->list = g_list_append(Data->list, "First ");
    

    If you want to use it is a variable, you need to change things to:

    struct _data
    {
      Glist list;
    } Data;
    

    When you do that, Data is not a pointer, so you would access it’s data like this (notice that you’re using . instead of ->):

    gboolean build_list()
    {
    Data.list = g_list_append(Data.list, “First “);

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to make this data variable global: $.ajax({ url: get_data.php, cache: false, dataType:
We have a need to access kernel global vars in net/ipv4/af_inet.c that are not
I have a vector declared as a global variable that I need to be
I'm writing code in Visual C++ and I need to use a global variable.
I need some help in coding this in C# I have a list of
I have a table and populating it with object list then I need to
Have/Want List Matching Algorithm I am implementing an item trading system on a high-traffic
I have an application that uses data from a table which is almost always
I have a list of directory name and need to get the first letter
I have a big list of global variables that each have their own setup

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.