I have a window with button for start action. After i click the button window freeze, but I want to start spinner. It is in C language
我有一个带有开始动作按钮的窗口。点击按钮窗口冻结后,我想启动微调器。它是用C语言编写的
This is the button setting.
这是按钮设置。
g_signal_connect(button, "clicked", G_CALLBACK(setVPN), entry);
function setVPN:
const gchar *vpn;
gtk_spinner_start(GTK_SPINNER(spinner)); //start spinner
gtk_label_set_markup(GTK_LABEL(msg), "<span foreground=\"#000000\">Probýhá změna VPN...</span>");
vpn = gtk_entry_get_text(GTK_ENTRY(entry));
char *ask; // Create system aks
ask = malloc(30+strlen(vpn));
strcpy(ask, "bash /bin/VPNSet/makeFile.sh ");
strcat(ask, vpn);
system(ask);
free(ask);
gtk_label_set_markup(GTK_LABEL(msg), "<span foreground=\"#00EE00\">Hotovo: VPN bylo změněno</span>");
//message("Uspěch","VPN bylo změněno.");
gtk_spinner_stop(GTK_SPINNER(spinner)); //stop spinner
return;
Fucntion working OK. But spinner dont start, and first message don´t show. This action for spinner and set lable window do after return. I try to do as a new process but that alternative dont function.
Fucntion工作正常。但旋转器不开始,第一条消息不显示。返回后,对旋转器和设置标签窗口执行此操作。我尝试做一个新的过程,但该替代方案不起作用。
Thanks for help.
感谢帮助。
1 个解决方案
#1
3
GTK+ does its work, i.e. rendering of widgets and so on, when your code is not running. It's single-threaded, if your program is stuck inside system()
there's no way for GTK+ to get CPU to do work, like drawing the spinner.
当你的代码没有运行时,GTK +会完成它的工作,即呈现小部件等等。它是单线程的,如果你的程序卡在系统内部(),那么GTK +就无法让CPU去做工作,就像绘制微调器一样。
You must use asynchronuous I/O.
您必须使用异步I / O.
Also, just use g_strdup_printf()
to build the string.
另外,只需使用g_strdup_printf()来构建字符串。
#1
3
GTK+ does its work, i.e. rendering of widgets and so on, when your code is not running. It's single-threaded, if your program is stuck inside system()
there's no way for GTK+ to get CPU to do work, like drawing the spinner.
当你的代码没有运行时,GTK +会完成它的工作,即呈现小部件等等。它是单线程的,如果你的程序卡在系统内部(),那么GTK +就无法让CPU去做工作,就像绘制微调器一样。
You must use asynchronuous I/O.
您必须使用异步I / O.
Also, just use g_strdup_printf()
to build the string.
另外,只需使用g_strdup_printf()来构建字符串。