新窗口没有在按钮回调的fltk中打开

时间:2017-01-23 14:04:25

标签: c++ fltk

我创建了一个按钮,单击该按钮将通过回调打开一个新窗口,但是当单击此按钮时没有任何反应,但是当它被释放时,它会闪烁新窗口并且不允许我在新窗口中看到内容。请任何帮助将不胜感激。

回调

//Callback for advanced search
static void ad_cb(Fl_Button *theButton, void*)
{
    Fl_Window adw (10,10,600,400);
    Fl_Button  adcc (30,40,120,20,"Advanced Search");
    adcc.tooltip ("Make advanced search");
    adw.show();


}

按钮

Fl_Button  ad (30,460 + 40,120,20,"Advanced Search");
    ad.tooltip ("Make advanced search");
    ad.callback((Fl_Callback*)ad_cb);

1 个答案:

答案 0 :(得分:1)

函数退出后立即调用析构函数。这就是你看到闪光灯的原因。将其更改为

//Callback for advanced search
static void ad_cb(Fl_Button *theButton, void*)
{
    Fl_Window* adw = new Fl_Window (10,10,600,400);
    Fl_Button*  adcc = new Fl_Button (30,40,120,20,"Advanced Search");
    adcc->tooltip ("Make advanced search");
    adw->show();
}

您可以通过点击顶角的x来关闭窗口。