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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:24:23+00:00 2026-05-24T06:24:23+00:00

// gcc -o 0 $(pkg-config –cflags –libs gtk+-2.0) 1.c #include <gtk/gtk.h> #include <gdk/gdkkeysyms.h> struct

  • 0
// gcc -o 0 $(pkg-config --cflags --libs gtk+-2.0) 1.c
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
struct tst
{
    GtkWidget *win, *w2, *hb, *vb, *ent, *btn, *b2, *pbar;
    GtkAccelGroup *acc;
};
GCancellable *can1;
GError *err1;
GThread *t1;
static void t1_stop (struct tst *prg)
{
    g_cancellable_cancel (can1);
    can1 = NULL;
}
gpointer t1_do (gpointer ptr1)
{
    struct tst *prg = (gpointer)ptr1;
    g_file_copy (g_file_new_for_path ("/1.avi"), g_file_new_for_path ("/2.avi"), G_FILE_COPY_NOFOLLOW_SYMLINKS, can1, NULL, NULL, &err1);
    if (err1 != NULL) g_error_free (err1);
    gtk_widget_destroy (prg->w2);
}
static void window_pbar (struct tst *prg)
{
    prg->w2 = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    prg->hb = gtk_hbox_new (FALSE, 0);
    prg->pbar = gtk_progress_bar_new ();
    prg->b2 = gtk_button_new_with_label ("Cancel");
    gtk_container_add (GTK_CONTAINER (prg->w2), GTK_WIDGET (prg->hb));
    gtk_window_set_position (GTK_WINDOW (prg->w2), GTK_WIN_POS_CENTER);
    gtk_box_pack_start (GTK_BOX (prg->hb), GTK_WIDGET (prg->pbar), FALSE, FALSE, 0);
    gtk_box_pack_start (GTK_BOX (prg->hb), GTK_WIDGET (prg->b2), FALSE, FALSE, 0);
    g_signal_connect_swapped (prg->w2, "delete_event", G_CALLBACK (t1_stop), prg);
    g_signal_connect_swapped (prg->b2, "clicked", G_CALLBACK (t1_stop), prg);
    gtk_widget_show_all (GTK_WIDGET (prg->w2));
    can1 = g_cancellable_new ();
    err1 = NULL;
    t1 = g_thread_create (t1_do, (gpointer)prg, TRUE, NULL);
}
static void window_new ()
{
    struct tst *prg = g_new0 (struct tst, 1);
    prg->win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    prg->vb = gtk_vbox_new (FALSE, 0);
    prg->btn = gtk_button_new_with_label ("start");
    gtk_container_add (GTK_CONTAINER (prg->win), GTK_WIDGET (prg->vb));
    gtk_box_pack_start (GTK_BOX (prg->vb), GTK_WIDGET (prg->btn), FALSE, FALSE, 0);
    g_signal_connect (prg->win, "delete_event", G_CALLBACK (gtk_main_quit), NULL);
    g_signal_connect_swapped (prg->btn, "clicked", G_CALLBACK (window_pbar), prg);
    gtk_window_set_title (GTK_WINDOW (prg->win), "Test program");
    gtk_window_set_position (GTK_WINDOW (prg->win), GTK_WIN_POS_CENTER);
    gtk_widget_show_all (GTK_WIDGET (prg->win));
    gtk_main ();
}
int main (int argc, char *argv[])
{
    gtk_init (&argc, &argv);
    window_new ();
    return 0;
}

This program is an example. When ‘start’ button is clicked the program creates a window with progress bar and ‘cancel’ button, and make a thread to copy /1.avi to /2.avi, but because of /1.avi doesn’t exist the program will write ‘Error!’ on terminal and close the progress bar window.
But there is one problem in this program. While I click ‘start’ button many times somewhen the program writes another error messages on terminal. Sometimes the messages are about GDK, sometimes about GObject, and sometimes about GTK+. And sometimes program itself is freezed or crashed.

// gcc -o 0 $(pkg-config --cflags --libs gtk+-2.0) 1.c
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
struct tst
{
    GtkWidget *win, *w2, *hb, *vb, *ent, *btn, *b2, *pbar;
    GtkAccelGroup *acc;
};
GCancellable *can1;
GError *err1;
GThread *t1;
static void t1_stop (struct tst *prg)
{
    g_cancellable_cancel (can1);
    can1 = NULL;
}
gpointer t1_do (gpointer ptr1)
{
    struct tst *prg = (gpointer)ptr1;
    g_file_copy (g_file_new_for_path ("/1.avi"), g_file_new_for_path ("/2.avi"), G_FILE_COPY_NOFOLLOW_SYMLINKS, can1, NULL, NULL, &err1);
    if (err1 != NULL) g_error_free (err1);
    gtk_widget_destroy (prg->w2);
}
static void window_pbar (struct tst *prg)
{
    prg->w2 = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    prg->hb = gtk_hbox_new (FALSE, 0);
    prg->pbar = gtk_progress_bar_new ();
    prg->b2 = gtk_button_new_with_label ("Cancel");
    gtk_container_add (GTK_CONTAINER (prg->w2), GTK_WIDGET (prg->hb));
    gtk_window_set_position (GTK_WINDOW (prg->w2), GTK_WIN_POS_CENTER);
    gtk_box_pack_start (GTK_BOX (prg->hb), GTK_WIDGET (prg->pbar), FALSE, FALSE, 0);
    gtk_box_pack_start (GTK_BOX (prg->hb), GTK_WIDGET (prg->b2), FALSE, FALSE, 0);
    g_signal_connect_swapped (prg->w2, "delete_event", G_CALLBACK (t1_stop), prg);
    g_signal_connect_swapped (prg->b2, "clicked", G_CALLBACK (t1_stop), prg);
    gtk_widget_show_all (GTK_WIDGET (prg->w2));
    can1 = g_cancellable_new ();
    err1 = NULL;
    t1 = g_thread_create (t1_do, (gpointer)prg, TRUE, NULL);
    g_thread_join (t1);
}
static void window_new ()
{
    struct tst *prg = g_new0 (struct tst, 1);
    prg->win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    prg->vb = gtk_vbox_new (FALSE, 0);
    prg->btn = gtk_button_new_with_label ("start");
    gtk_container_add (GTK_CONTAINER (prg->win), GTK_WIDGET (prg->vb));
    gtk_box_pack_start (GTK_BOX (prg->vb), GTK_WIDGET (prg->btn), FALSE, FALSE, 0);
    g_signal_connect (prg->win, "delete_event", G_CALLBACK (gtk_main_quit), NULL);
    g_signal_connect_swapped (prg->btn, "clicked", G_CALLBACK (window_pbar), prg);
    gtk_window_set_title (GTK_WINDOW (prg->win), "Test program");
    gtk_window_set_position (GTK_WINDOW (prg->win), GTK_WIN_POS_CENTER);
    gtk_widget_show_all (GTK_WIDGET (prg->win));
    gtk_main ();
}
int main (int argc, char *argv[])
{
    gtk_init (&argc, &argv);
    window_new ();
    return 0;
}

So I modified some parts of program. Now the problem not occurs though I click ‘start’ button many times, but I met another problem. When I can copy /1.avi to /2.avi, if I click ‘start’ button then program copies /1.avi to /2.avi but during this process the program window freezes, and progress bar window doesn’t appear(On first example this problem isn’t occured).

What should I do to make this program to meet neither of two problems?

  • 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-24T06:24:24+00:00Added an answer on May 24, 2026 at 6:24 am

    The immediate problem I can see with your code is that you are calling a Gtk function in t1_do which is run from the secondary thread without enclosing it in gtk_thread_enter (); gtk_thread_leave ();

    The general rule is that you should never call a UI function from a thread that isn’t the main UI thread. Until you fix that problem you could just get completely random errors and behaviour

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

Sidebar

Related Questions

// gcc z.c -o z $(pkg-config --cflags --libs gtk+-2.0) #include <string.h> #include <gtk/gtk.h> #include
I can't get gtkmozembed to work: #include <gtk/gtk.h> #include <gdk/gdk.h> #include <gtkmozembed.h> #include <stdlib.h>
I have installed GCC-10.7-v2.pkg found at https://github.com/kennethreitz/osx-gcc-installer/downloads And I have removed Xcode completely following
gcc -o fig fig.c -I./include ./lib/libmylib.a -g gcc -g fig.c -o fig -I./include ./lib/libmylib.a
GCC is a very well respected multi-language compiler (from what I've gathered). One thing
gcc I am just getting back into c programming and I am just practicing
GCC's recent support for atomic operations (as described here ) is great, and is
gcc 4.4.2 c89 I have a wave file: 8000 Hz 16 bit I am
gcc 4.4.2 I have the following code: char channels[] = NumberOfChannel = [2]; sscanf(channels,
gcc 4.4.2 / Visual Studio C++ 2008 I have been using cmake on linux,

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.