[gtk+] run function in another thread than gui
- by sterh
Hello,
I have simple C/gtk+ application. I have function in this app which load image in gtkimageview widget:
gboolean
main_win_open( MainWin* mw, const char* file_path)
{
...
//loading and displaing image in gtkimageview
...
}
The loading image is work, but i need to run this function in another thread then main gui form;
I have function:
void*
argument_thread(void *args)
{
Data *data = (Data*)args;
gdk_threads_enter();
main_win_open (data->win,data->argv);
gdk_threads_leave();
}
Data it's structure for main_win_open function arguments:
typedef struct _Data
{
MainWin *win;
char* argv;
} Data;
Then in main function i create thread and run it:
int main(int argc, char** argv)
{
GError* err;
GThread* thread;
Data data;
MainWin *win;
// init thread support
if(!g_thread_supported())
g_thread_init(NULL);
gdk_threads_init();
// init GTK+
gtk_init (&argc, &argv);
win = (MainWin*)main_win_new();
gtk_widget_show(GTK_WIDGET(win));
data.win = win;
data.argv = argv[1];
if (argc == 2)
{
thread = g_thread_create((GThreadFunc)argument_thread,&data,FALSE, &err);
}
gdk_threads_enter();
gtk_main();
gdk_threads_leave();
}
But when i try to run app from command line and try to load big-size image, gui is blocking.
What's wrong?
Thank you.