how to make the function wait for some thing to continue

Mar 7, 2011 at 11:00am
Hi,
I have a functions like below
1
2
3
4
5
6
7
8
void Function()
{
    for(int i = 0; i < count; ++i)
   {
        if(check_i( int_array[i] ) )
            function_gui( i );
    }
}


In the code above I'm checking in the array for some particular values, when it is valid i have to display it on GUI dialog, with some text box and next button on. here I wants that the iteration in the Function() continues only after the next button is pressed else it should wait for the button to be pressed. I have read somethings about the busy waiting using semaphore. But please let me know any standard way for implementing this.

Thanks a lot!
Last edited on Mar 7, 2011 at 11:01am
Mar 7, 2011 at 11:08am
u can use getch() (in ur if condition )to pause ur program and print that value....whenever a key is pressed the loop will continue
Mar 7, 2011 at 11:12am
I need this in GUI app, where the value of i is displayed on the TextBox from the loop, and I wants the loop to continue only when next button is pressed else it remain pause.
Mar 7, 2011 at 11:29am
Normally such functions provide the means to stay open and return the appropriate code when a button like "Cancel" is pushed.

For example, Qt's QDialog has a method called exec(). This open the dialog and block the application until is is closed with a rejection or acception. exec() then returns either QDialog::Accepted or QDialog::Rejected.

Which GUI Framework are you using?

Thomas
Mar 7, 2011 at 11:42am
Thanks for your reply first! Yeah you are absolutely right! But in my case things are bit different.

I am using JUCE for the GUI but its not in standalone application as I am using this for making plug-In.

And My scenario is bit different, and I have written such to make the thing simpler.

I have function which puts text in a text frame and enables all the control on the panel(MODALESS DIALOG) and keep on putting the text on it. I want to intercept the loop so that It continues only when some buttons on the panel gets pressed.
And I want to be suggested with some standard way of handling this situation.
Last edited on Mar 7, 2011 at 11:43am
Mar 7, 2011 at 11:54am
But that's exactly what the dialog should do for you. The dialog should NOT return until the user clicks on a button. This is meant by "block the application". The loop CANNOT continue unless the dialog is closed. What I suspect is: You want the dialog to be visible all the time right? The let the loop continue, update the text in the dialog - all while the dialog is shown. Correct? Or is it acceptable for you to close the dialog in between invocations in the loop?

I can't figure out if "MODALESS DIALOG" means modal or non-modal. Do you want a modal dialog? I suggest that you do use a modal dialog.

Is the user supposed to enter text in the dialog or are you simply filling the TextBox within the dialog yourself?
Mar 7, 2011 at 12:20pm
Dont use a loop in your function.
Have it do only one step at a time.
Continue calling it from the NextButtonEventHandler() until it returns true.

Like
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
bool Function()
{
    static int i;

    i++;
    if(i>=count) // done
    {
        i=0;
        return true;
    }
    else // still work to do
    {
        if(check_i( int_array[i] ) )
            function_gui( i );
        return false;
    }
}
Topic archived. No new replies allowed.