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

  • Home
  • SEARCH
  • 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 9208837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:42:12+00:00 2026-06-18T00:42:12+00:00

I am writing a code in gtk, that opens a file, parses it as

  • 0

I am writing a code in gtk, that opens a file, parses it as

/*Open and scan the file*/
fd = open (filename, O_RDWR);
scanner = g_scanner_new (NULL);
g_scanner_input_file (scanner, fd);
....
....
g_scanner_destroy (scanner);
gtk_label_set_text(GTK_LABEL(flabel), filename);
close (fd);  

and view it in a treeview(in a separate function). The treeview is as:

store = gtk_list_store_new (NUM_COLS, G_TYPE_STRING, G_TYPE_STRING,
                                                G_TYPE_STRING, 
                                                G_TYPE_STRING, 
                                                G_TYPE_STRING);

  tree = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store));
/* #1: KEY COLUMN */  
  cell = gtk_cell_renderer_text_new ();
  g_object_set (cell,
                "editable", TRUE,
                NULL);
  g_signal_connect (cell, 
      "edited",G_CALLBACK(cell_edited), 
      tree);
  g_object_set_data (G_OBJECT (cell), 
      "column", GINT_TO_POINTER (COL_BIB_KEY));

  GtkTreeViewColumn *col_key,*col_year,*col_type,*col_auth,*col_pub;
  col_key=gtk_tree_view_column_new_with_attributes (
      "Key", cell,
      "text", COL_BIB_KEY,
      NULL);
  gtk_tree_view_column_set_sort_column_id( col_key, ID_KEY);
  gtk_tree_view_append_column (GTK_TREE_VIEW (tree), col_key);
  gtk_tree_view_column_set_max_width  (col_key,100);

where the cell_edited is a function to write the data in the treeview itself:

void cell_edited(GtkCellRendererText *renderer,
    gchar *path,
    gchar *new_text,
    GtkTreeView *treeview)
{
  guint column;
  GtkTreeIter iter;
  GtkTreeModel *model;
  gpointer columnptr = g_object_get_data(G_OBJECT(renderer), "column");
  column = GPOINTER_TO_UINT(columnptr);

  if (g_ascii_strcasecmp (new_text, "") != 0)
  {
    model = gtk_tree_view_get_model (treeview);
    if (gtk_tree_model_get_iter_from_string (model, &iter, path))
      gtk_list_store_set (GTK_LIST_STORE (model), &iter, column, new_text, -1);
  }
}

The problem is I also want to update the data in the file. Can I get some help on how to do that?

  • 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-06-18T00:42:13+00:00Added an answer on June 18, 2026 at 12:42 am

    You’ll have to build the contents of the file in the same format that you need, then write it out.

    One way you could do it is using GString to build the contents and then use g_file_set_contents to write it out.

    // Create GString
    GString *str = g_string_new ("");
    
    // Iterate over the list store
    GtkTreeIter iter;
    gboolean valid;
    
    for (valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter);
         valid;
         valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &iter)) {
        char *string0, *string1, *string2, *string3, *string4;
    
        gtk_tree_model_get (GTK_TREE_MODEL (store), &iter,
                            0, &string0,
                            1, &string1,
                            2, &string2,
                            3, &string3,
                            4, &string4,
                            -1);
    
        // I don't know the format of your file, so I'm just going to separate them with a comma
        g_string_append_printf (str, "%s,%s,%s,%s,%s\n", string0, string1, string2, string3, string4);
    
        // gtk_tree_model_get copies strings, so free them
        g_free (string0);
        g_free (string1);
        g_free (string2);
        g_free (string3);
        g_free (string4);
    }
    
    // Set the file contents atomically, add error checking
    g_file_set_contents (filename, str->str, -1, NULL);
    
    // Free the GString
    g_string_free (str, TRUE);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While writing code in a file that would comprise of PHP, HTML, CSS &
I'm writing code in PHP that requires including a config.php file depending on the
I'mm writing gtk code. I often have short callbacks that don't need to be
I am writing code to login into router and grab some settings. My code,that
I am writing code in ASP.NET . I have a button that is clickable
When writing code in Python, how can you write something next to it that
I'm writing code that will run on Linux, OS X, and Windows. It downloads
I'm writing code that must run same kernel on GTX690 (dual chip) board. Since
I am writing code to read and write a text file. But when I
I am writing some code where I need to drop down from GTK+ to

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.