问题描述:

I've come across some weird behaviour in FLTK and am trying to work out how to solve it. Essentially I have this format in main:

int main(){

Fl::lock(); //will be doing multithreading

win= new Fl_Double_Window(0.5*(Fl::w()-w),0.5*(Fl::h()-h),w,h, "Program");

win->begin();

Fl_Tabs* oo = new Fl_Tabs(10,20,win->w()-20,win->h()-140);

{Fl_Group* a = new Fl_Group(20, 40, oo->w(),oo->h(), "Send to ");

Fl_Box* control_box= Fl_Box(x,y,w,h,"Comparison Test");

Fl_Button* button = Fl_Button(x,y,w,h,"run");

button->callback((Fl_Callback*) run_cb);

a->end();

}

{Fl_Group* b = new Fl_Group(20, 40, oo->w(),oo->h(), "");

Fl_Box* box= Fl_Box(x,y,w,h,"Warning");

box->hide();

//user does something here which causes box to box->show(); displaying warning

b->end();

}

oo->end();

win->end();

return Fl::run();

}

//functions

void run_cb(Fl_Widget* widget,void* data){

fl_create_thread(thread1,calculate,NULL);

}

void* calculate(void* data){

//do some calculations

Fl::lock();

//update some data structures

Fl::unlock();

//PROBLEM IS HERE<--------------------

}

Now, my problem is that at this "<-----------" location I want to then hide the warning box which is in tab b.

Everything I try whether it be Fl::awake(), Fl::awake(&check_from_thread) where check_fom_thread is the appropriate function (containing every permutation of box->hide() Fl::check(), Fl::flush() etc.)to be run in the parent (GUI) thread, or box->hide() in the thread , inside or outside the lock unlock pair, before and after an Fl::awake() call (again inside or outside the lock unlock pair) fails to get the functionality right which is:

The warning box is shown, I switch to the first tab, I press the button which runs the callback and then thread, but before it finishes I switch back to the second tab where I expect the warning box to disappear upon completion of the threaded function call. BUT it doesn't get hidden. However, if, after the thread has finished, I then switch to tab a then back to tab b it then is becomes hidden.

On the other hand if instead of hiding 'box' in tab b, I hide 'control_box' in tab a, pretty much every permutation I described above works fine.

I have no idea why it would be doing this.

Does anyone have any ideas?

I thought it might be because under the hood Fl_Tabs is using ->hide() and ->show() meaning there might be some overriding of widget properties, but this doesn't make sense because if I switch to tab b before the thread which hides 'box' ends, at the time of the update tab b is shown as is widget 'box', but box fails to hide. But the same situation applies when a thread run from a ends up hiding 'control_box' at the time of the update: tab a is shown as is 'control_box' but that situation works. Tearing my hair out!...

网友答案:

I have no idea why the above happens, but a way that was supposed to work (calling the redraw() method associated with the parent widget of the box I wanted to hide) didn't, but finally what did was calling redraw() on the overall parent window. Not particularly elegant, but it does the job.

相关阅读:
Top