【发布时间】:2021-12-17 18:48:45
【问题描述】:
我正在为显示消息创建类 10 秒,然后关闭表单。
我使用g_timeout_add_seconds 函数进行时间延迟。在编译时我面临如下错误:
msgbox.cpp:84:72: error: invalid use of void expression
int a = g_timeout_add_seconds(1, this->Label(i), (gpointer)this);
代码如下:
void Msgbox::LabelUpdate(void)
{
int i = 1;
while(i <= 10)
{
g_timeout_add_seconds(1, this->Label(i), (gpointer)this);
i++;
}
gtk_widget_set_sensitive(close_btn , TRUE);
gtk_widget_grab_focus(close_btn);
}
void Msgbox::Label(int time)
{
char buf[256];
sprintf(buf, "<span color=\"purple\"><b> Time to wait : %d secs </b></span>", time);
gtk_label_set_markup (GTK_LABEL(msg_lbl), buf);
}
请帮助! 提前致谢!
【问题讨论】:
-
msgbox.cpp:84:72这是哪一行?这是整个代码吗? -
您显示的代码与您提供的错误消息不匹配。请尝试创建一个正确的minimal reproducible example 向我们展示,并将该示例中完整且完整的构建输出复制粘贴到问题中。并在出现错误的行添加注释。
-
话虽如此,你的
Label函数返回了什么?将该结果用作函数调用的参数是否有意义?