How to transfer data sequence between forms in Qt



  • Assume I have 2 forms in a Qt application. I need to transfer data between 2 forms many times so I used the loop to do this. I just wanna get result from Form 2 before Form 1 is continue to loop. This is my desired intention:

    !http://i249.photobucket.com/albums/gg220/HienBoo/form2.png(Transfer data)!

    When I used the loop normally, the loop began at i = 1 and sent data to Form 2. Before Form 2 returned result to Form 1, Form 1 was continue to send data with i = 2.

    Could you give me some solutions?

    Thanks!



  • Hi, can you tell us which problem you have encountered?

    @
    for (int i=0; i<3; ++i)
    ret = form2.doSomething();
    @



  • for(int i = 0; i < 5; i++)
    {
    callToFunction2();
    qApp->processEvents();
    }

    processevents is wait till we get the restult from form 2.

    hope this will help.


  • Lifetime Qt Champion

    [quote author="monsingh" date="1375164656"]for(int i = 0; i < 5; i++)
    {
    callToFunction2();
    qApp->processEvents();
    }

    processevents is wait till we get the restult from form 2.
    [/quote]

    No it won't, processEvent will just process the pending events.

    Like 1+1=2 suggested, all the processing should be done before the function returns



  • Hi SGaist,

    try this small program: we get the order of execution.

    write the for loop in construcor

    for(int i = 0; i < 5; i++)
    {
    qDebug() << callToFunction2(i);
    qApp->processEvents();
    }

    int MainWindow::callToFunction2(int i)
    {
    qDebug()<< "order :" << ++i;
    return 5;
    }


  • Lifetime Qt Champion

    Wait, we are not understanding each-other right.

    Do you mean that processEvent will be called after callToFunction2 has returned ? In that case I agree

    PS: please enclose your code with coding tags to make it readable


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.