GTK4 进度条不更新
GTK4 progress bar is not updating
用 C 编写的 GTK4 应用程序有问题 - 进度条值未更新。
在应用程序 window 中,我首先展示了一些从 xml 加载的数据。确认此屏幕后,我用数据隐藏 vBox 并创建
新的进度条,我想根据进度实现。但是 progressBar 显示值为 0。整个时间显示为零
另一个计数,然后应用程序进入其第三个屏幕(没有进度条达到 100% 值)。
当我想要更新进度条时,我发出自定义信号“custom-signal-update-progress”。我可以看到应用程序处于回调函数中
(来自命令行输出)。我还可以看到发送到进度条的百分比值也增加了。
此行为在 win10 中存在,但在 xubuntu 21.10 中也存在。
请问有人能给我一些解决方法的建议吗?
部分代码:
static void
update_progress (gpointer data) {
printf("update_progress value %f index %d \n",progressValue, checkedTestPlace);
gpointer bar = g_object_get_data(G_OBJECT(data), "bar");
gpointer window = g_object_get_data(G_OBJECT(data), "window");
gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(bar),progressValue);
if (progressValue >= 1.0) {
g_signal_emit_by_name(window, "custom-signal-hide-progress");
};
}
static gboolean
start_test_pcace_checking (gpointer data) {
gpointer window = g_object_get_data(G_OBJECT(data), "window");
unsigned int vectSize = testPlaceVector.size();
for (unsigned int i = 0; i < vectSize; ++i) {
progressValue = (gfloat) (i+1) / (gfloat) vectSize;
printf("we are sending signal for update \n");
g_signal_emit_by_name(window, "custom-signal-update-progress");
if (testPlaceVector.at(i).defaultValue.compare("YES")==0) {
//check_test_place (testPlaceVector.at(i).address, testPlaceVector.at(i).name);
}
sleep( 1 );
}
return false;
}
static void
close_chooser_window (gpointer data) {
cout << "test places changes:"<<endl;
vypis_vektor(testPlaceVector);
gpointer window = g_object_get_data(G_OBJECT(data), "window");
gpointer box = g_object_get_data(G_OBJECT(data), "box");
gtk_widget_hide(GTK_WIDGET(box));
GtkWidget *vBox;
GtkWidget *bar;
GtkWidget *lab;
vBox = gtk_box_new (GTK_ORIENTATION_VERTICAL,3);
gtk_box_set_homogeneous (GTK_BOX (vBox), TRUE);
gtk_window_set_child (GTK_WINDOW (window), vBox);
lab = gtk_label_new ("checking proggress");
gtk_box_append (GTK_BOX (vBox), lab);
bar = gtk_progress_bar_new ();
gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(bar),0.0);
gtk_progress_bar_set_show_text (GTK_PROGRESS_BAR(bar), TRUE);
gtk_box_append (GTK_BOX (vBox), bar);
lab = gtk_label_new ("");
gtk_box_append (GTK_BOX (vBox), lab);
g_object_set_data(G_OBJECT(window), "window",window);
g_object_set_data(G_OBJECT(window), "box",vBox);
g_object_set_data(G_OBJECT(window), "bar",bar);
g_timeout_add(200,start_test_pcace_checking,window);
}
static void
app_activate (GApplication *app, gpointer user_data) {
GtkWidget *win;
GtkWidget *vBox;
GtkWidget *btn;
GtkWidget *chBtn;
win = gtk_application_window_new (GTK_APPLICATION (app));
gtk_window_set_title (GTK_WINDOW (win), "Git Status - choose what check");
gtk_window_set_default_size (GTK_WINDOW (win), 400, 300);
testPlaceVector = load_config_xml();
vBox = gtk_box_new (GTK_ORIENTATION_VERTICAL,3);
gtk_box_set_homogeneous (GTK_BOX (vBox), TRUE);
gtk_window_set_child (GTK_WINDOW (win), vBox);
for (unsigned int i = 0; i < testPlaceVector.size(); ++i)
{
chBtn = gtk_check_button_new_with_label (testPlaceVector.at(i).name.c_str());
if ( testPlaceVector.at(i).defaultValue.compare("YES") ==0) {
gtk_check_button_set_active(GTK_CHECK_BUTTON(chBtn),true);
}
gtk_box_append (GTK_BOX (vBox), chBtn);
g_signal_connect(G_OBJECT(chBtn),"toggled",G_CALLBACK(check_button_clicked),chBtn);
}
btn = gtk_button_new_from_icon_name("emblem-default");
//gtk_button_set_label(GTK_BUTTON(btn),"OK");
gtk_box_append (GTK_BOX (vBox), btn);
//tu si nadefinujeme nas signal - kterej poslem, kdyz dozkoumame jeden testovaci stav a budem potrebovat aktualizovat progress bar
g_signal_new("custom-signal-update-progress", G_TYPE_OBJECT, G_SIGNAL_RUN_FIRST, 0, NULL, NULL, g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER);
//tu priradime obsluznou proceduru k nasemu signalu
g_signal_connect(win, "custom-signal-update-progress", G_CALLBACK(update_progress), NULL);
g_signal_new("custom-signal-hide-progress", G_TYPE_OBJECT, G_SIGNAL_RUN_FIRST, 0, NULL, NULL, g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER);
g_signal_connect(win, "custom-signal-hide-progress", G_CALLBACK(hide_progress), win);
g_object_set_data(G_OBJECT(btn), "window",win);
g_object_set_data(G_OBJECT(btn), "box",vBox);
g_signal_connect(G_OBJECT(btn), "clicked", G_CALLBACK(close_chooser_window), btn);
gtk_widget_show (win);
}
int
main (int argc, char **argv) {
GtkApplication *app;
int stat;
//app = gtk_application_new ("git.status.checker.gui", G_APPLICATION_FLAGS_NONE);
app = gtk_application_new ("Git.status.icon", G_APPLICATION_FLAGS_NONE);
g_signal_connect (app, "activate", G_CALLBACK (app_activate), NULL);
stat =g_application_run (G_APPLICATION (app), argc, argv);
g_object_unref (app);
return stat;
}
命令行输出:
we are sending signal for update
update_progress value 0,111111 index 0
we are sending signal for update
update_progress value 0,222222 index 0
we are sending signal for update
update_progress value 0,333333 index 0
we are sending signal for update
update_progress value 0,444444 index 0
we are sending signal for update
update_progress value 0,555556 index 0
we are sending signal for update
update_progress value 0,666667 index 0
we are sending signal for update
update_progress value 0,777778 index 0
we are sending signal for update
update_progress value 0,888889 index 0
we are sending signal for update
update_progress value 1,000000 index 0
Process returned 0 (0x0) execution time : 18.095 s
Press any key to continue.
我 post 这个问题也在 gnome.org - 和这些人一起 - 我们找到了解决方案。
如果有人对此感兴趣:
https://discourse.gnome.org/t/gtk4-progress-bar-is-not-updating/9317/3
用 C 编写的 GTK4 应用程序有问题 - 进度条值未更新。
在应用程序 window 中,我首先展示了一些从 xml 加载的数据。确认此屏幕后,我用数据隐藏 vBox 并创建 新的进度条,我想根据进度实现。但是 progressBar 显示值为 0。整个时间显示为零 另一个计数,然后应用程序进入其第三个屏幕(没有进度条达到 100% 值)。
当我想要更新进度条时,我发出自定义信号“custom-signal-update-progress”。我可以看到应用程序处于回调函数中 (来自命令行输出)。我还可以看到发送到进度条的百分比值也增加了。
此行为在 win10 中存在,但在 xubuntu 21.10 中也存在。
请问有人能给我一些解决方法的建议吗?
部分代码:
static void
update_progress (gpointer data) {
printf("update_progress value %f index %d \n",progressValue, checkedTestPlace);
gpointer bar = g_object_get_data(G_OBJECT(data), "bar");
gpointer window = g_object_get_data(G_OBJECT(data), "window");
gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(bar),progressValue);
if (progressValue >= 1.0) {
g_signal_emit_by_name(window, "custom-signal-hide-progress");
};
}
static gboolean
start_test_pcace_checking (gpointer data) {
gpointer window = g_object_get_data(G_OBJECT(data), "window");
unsigned int vectSize = testPlaceVector.size();
for (unsigned int i = 0; i < vectSize; ++i) {
progressValue = (gfloat) (i+1) / (gfloat) vectSize;
printf("we are sending signal for update \n");
g_signal_emit_by_name(window, "custom-signal-update-progress");
if (testPlaceVector.at(i).defaultValue.compare("YES")==0) {
//check_test_place (testPlaceVector.at(i).address, testPlaceVector.at(i).name);
}
sleep( 1 );
}
return false;
}
static void
close_chooser_window (gpointer data) {
cout << "test places changes:"<<endl;
vypis_vektor(testPlaceVector);
gpointer window = g_object_get_data(G_OBJECT(data), "window");
gpointer box = g_object_get_data(G_OBJECT(data), "box");
gtk_widget_hide(GTK_WIDGET(box));
GtkWidget *vBox;
GtkWidget *bar;
GtkWidget *lab;
vBox = gtk_box_new (GTK_ORIENTATION_VERTICAL,3);
gtk_box_set_homogeneous (GTK_BOX (vBox), TRUE);
gtk_window_set_child (GTK_WINDOW (window), vBox);
lab = gtk_label_new ("checking proggress");
gtk_box_append (GTK_BOX (vBox), lab);
bar = gtk_progress_bar_new ();
gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(bar),0.0);
gtk_progress_bar_set_show_text (GTK_PROGRESS_BAR(bar), TRUE);
gtk_box_append (GTK_BOX (vBox), bar);
lab = gtk_label_new ("");
gtk_box_append (GTK_BOX (vBox), lab);
g_object_set_data(G_OBJECT(window), "window",window);
g_object_set_data(G_OBJECT(window), "box",vBox);
g_object_set_data(G_OBJECT(window), "bar",bar);
g_timeout_add(200,start_test_pcace_checking,window);
}
static void
app_activate (GApplication *app, gpointer user_data) {
GtkWidget *win;
GtkWidget *vBox;
GtkWidget *btn;
GtkWidget *chBtn;
win = gtk_application_window_new (GTK_APPLICATION (app));
gtk_window_set_title (GTK_WINDOW (win), "Git Status - choose what check");
gtk_window_set_default_size (GTK_WINDOW (win), 400, 300);
testPlaceVector = load_config_xml();
vBox = gtk_box_new (GTK_ORIENTATION_VERTICAL,3);
gtk_box_set_homogeneous (GTK_BOX (vBox), TRUE);
gtk_window_set_child (GTK_WINDOW (win), vBox);
for (unsigned int i = 0; i < testPlaceVector.size(); ++i)
{
chBtn = gtk_check_button_new_with_label (testPlaceVector.at(i).name.c_str());
if ( testPlaceVector.at(i).defaultValue.compare("YES") ==0) {
gtk_check_button_set_active(GTK_CHECK_BUTTON(chBtn),true);
}
gtk_box_append (GTK_BOX (vBox), chBtn);
g_signal_connect(G_OBJECT(chBtn),"toggled",G_CALLBACK(check_button_clicked),chBtn);
}
btn = gtk_button_new_from_icon_name("emblem-default");
//gtk_button_set_label(GTK_BUTTON(btn),"OK");
gtk_box_append (GTK_BOX (vBox), btn);
//tu si nadefinujeme nas signal - kterej poslem, kdyz dozkoumame jeden testovaci stav a budem potrebovat aktualizovat progress bar
g_signal_new("custom-signal-update-progress", G_TYPE_OBJECT, G_SIGNAL_RUN_FIRST, 0, NULL, NULL, g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER);
//tu priradime obsluznou proceduru k nasemu signalu
g_signal_connect(win, "custom-signal-update-progress", G_CALLBACK(update_progress), NULL);
g_signal_new("custom-signal-hide-progress", G_TYPE_OBJECT, G_SIGNAL_RUN_FIRST, 0, NULL, NULL, g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER);
g_signal_connect(win, "custom-signal-hide-progress", G_CALLBACK(hide_progress), win);
g_object_set_data(G_OBJECT(btn), "window",win);
g_object_set_data(G_OBJECT(btn), "box",vBox);
g_signal_connect(G_OBJECT(btn), "clicked", G_CALLBACK(close_chooser_window), btn);
gtk_widget_show (win);
}
int
main (int argc, char **argv) {
GtkApplication *app;
int stat;
//app = gtk_application_new ("git.status.checker.gui", G_APPLICATION_FLAGS_NONE);
app = gtk_application_new ("Git.status.icon", G_APPLICATION_FLAGS_NONE);
g_signal_connect (app, "activate", G_CALLBACK (app_activate), NULL);
stat =g_application_run (G_APPLICATION (app), argc, argv);
g_object_unref (app);
return stat;
}
命令行输出:
we are sending signal for update
update_progress value 0,111111 index 0
we are sending signal for update
update_progress value 0,222222 index 0
we are sending signal for update
update_progress value 0,333333 index 0
we are sending signal for update
update_progress value 0,444444 index 0
we are sending signal for update
update_progress value 0,555556 index 0
we are sending signal for update
update_progress value 0,666667 index 0
we are sending signal for update
update_progress value 0,777778 index 0
we are sending signal for update
update_progress value 0,888889 index 0
we are sending signal for update
update_progress value 1,000000 index 0
Process returned 0 (0x0) execution time : 18.095 s
Press any key to continue.
我 post 这个问题也在 gnome.org - 和这些人一起 - 我们找到了解决方案。 如果有人对此感兴趣: https://discourse.gnome.org/t/gtk4-progress-bar-is-not-updating/9317/3