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 8841193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:39:08+00:00 2026-06-14T10:39:08+00:00

How do I check if a value already exists in a GtkListStore to avoid

  • 0

How do I check if a value already exists in a GtkListStore to avoid duplicates? Dynamically I get values from a database according to a users data input, but if the user types the same or similar word to a previously typed word, it can return the same result, making it so there are not any duplicates values into my GtkListStore.

Here’s the function that I’m using currently to add the values into GtkListStore:

static inline void update_c_list(struct al_t *new_list, size_t new_list_size)
{
  struct al_t *l = new_list;
  GtkTreeIter iter;
  size_t i = 0;

  for(; i < new_list_size; i++,l++) {

    if(/* magic to avoid double goes here */) {
    gtk_list_store_append(completionmodel, &iter);
    gtk_list_store_set(completionmodel, 
               &iter, C_NAME, l->name,
               C_NICK, FOO_STRING(l->foo),
               C_EMAIL, BAA_STRING(l->baa), -1);
    }
  }

  gtk_entry_completion_set_model(completion, GTK_TREE_MODEL(completionmodel));
}
  • 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-14T10:39:09+00:00Added an answer on June 14, 2026 at 10:39 am

    You need to iterate the list and find if same data exists in it.

    struct CListLooupStruct
    {
      gbolean b_found;
      struct al_t *l;
    }; 
    
    gbolean search_c_list_func(GtkTreeModel *model, 
                               GtkTreePath *path, 
                               GtkTreeIter *iter, 
                               gpointer data)
    {
       gchar name[MAX_NAME_LENGTH];
       CListLooupStruct* lookup = (CListLooupStruct*)data;
       gtk_tree_model_get (model, iter, 0, &name, -1)
       if (/*compare name to lookup->name */)
       { 
           lookup->b_found = TRUE;
           return TRUE;
       }
       return FALSE;
    }
    

    In your update_c_list() function you need to:

    ...
    CListLooupStruct c_list_lookup = { FALSE, new_list };    
    gtk_tree_model_foreach(completionmodel, search_c_list_func, &c_list_lookup);
    if (/* magic to avoid double */ c_list_lookup.b_found == FALSE )
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using this code to check whether a value (guid1) already exists in
I want to check the entered email id already exists in my database or
I'm attempting to check if a value exists in the choices tuple set for
I am trying to determine if the user entered value already exists in the
I have a variable, for example $total1. It has a value from the database,
I am trying to update a column in already exists MySQL table. The values
EDIT: Is there a way to check if the constraint already exists to determine
What is the best way of checking whether a value exists already before allowing
I use this to check in my registration page, if the email already exists
How to check a value IS NULL [or] = @param (where @param is null)

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.