Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Slot function not updating when not called from MainWindow function



  • I have a recurring function called seekvalue:
    @void MainWindow::seekvalue (double goal, double bound_lower, double bound_upper, double seek) {
    seek = bound_lower + (bound_upper - bound_lower) / 2;
    double goalseek;
    update_values(&goalseek, seek);
    if (abs(goalseek - goal) <= 0.0001)
    ;
    else if (goalseek < goal) {
    bound_lower = seek;
    seekvalue (goal, bound_lower, bound_upper, seek);
    ;
    }
    else if (goalseek > goal){
    bound_upper = seek;
    seekvalue(goal, bound_lower, bound_upper, seek);
    ;
    }
    else
    return;
    }@

    In its third statement, it calls update_values which is defined as:
    @void MainWindow::update_values(double* goalseek, double seek)
    {
    ui->doubleSpinBox_19->setValue(seek);
    update_output_table();
    *(goalseek) = ui->tableWidget_2->item(0,7)->text().toDouble();
    }@

    If the routine ran as intended, update_output_table() should update the value of tableWidget_2->item(0,7). However when debugging the routine, I find that *goalseek does not equal to tableWidget_2->item(0,7) which leads me to believe that update_output_table is not executed correctly.

    Are there any possible explanations as to why update_output_table() is not updating as expected? Note that the function itself is solid and works when in use elsewhere.



  • I don't see a reason why goalseek shouldn't be updated, as long as a valid pointer to a Double is passed to update_values(). However we have absolutely no idea what update_output_table() does. Furthermore, be aware that toDouble() returns 0.0 if it couldn't parse the string as a valid real number...

    I suggest you add this to your code for testing:
    @void MainWindow::seekvalue(...)
    {
    ...
    double goalseek;
    update_values(&goalseek, seek);
    qDebug("text = "%s"", ui->tableWidget_2->item(0,7)->text().toUtf8().constData());
    qDebug("goalseek = %f", goalseek);
    ...
    }@

    BTW: In your code Signals&Slots is not involved, so why "Slot" in the title?



  • You are correct that naming "slots" is out of context. Basically the functions are called through a slot connect statement.

    Also, there is no risk that toDouble cant parse the string as all input is strictly set as integers.

    I still cant find then solution here...



  • Well, did you add the suggested Debug prints and checked the outcome?



  • I didnt. I dont seem to sound lazy but it cant make a diffrence. But to be safe Ill try it when I get to my desktop PC tomorrow. Watch this space.


  • Moderators

    [quote author="DeanQt" date="1399300284"]it cant make a diffrence.[/quote]MuldeR didn't suggest it because it's the solution; he suggested it because it can provide clues to help you find a solution.



  • I added that code in but I always knew goalseek didnt update so nothing new.

    I have concluded that update_values() function is NOT being called. I know this because when I try and call it, the function has an exit() statement at the end and it doesnt execute. Why is it not being called?:

    @
    void MainWindow::update_output_table()
    {
    //some code...
    exit(0);
    }
    }

    void MainWindow::update_values(double* goalseek, double seek)
    {
    ui->doubleSpinBox_19->setValue(seek);
    update_output_table();
    *(goalseek) = ui->tableWidget_2->item(0,7)->text().toDouble();
    }

    void MainWindow::seekvalue (double goal, double bound_lower, double bound_upper, double seek) {
    seek = bound_lower + (bound_upper - bound_lower) / 2;
    double goalseek;
    update_values(&goalseek, seek);
    //qDebug("text = "%s"", ui->tableWidget_2->item(0,7)->text().toUtf8().constData());
    //qDebug("goalseek = %f", goalseek);
    if (abs(goalseek - goal) <= 0.0001)
    ;
    else if (goalseek < goal) {
    bound_lower = seek;
    seekvalue (goal, bound_lower, bound_upper, seek);
    ;
    }
    else if (goalseek > goal){
    bound_upper = seek;
    seekvalue(goal, bound_lower, bound_upper, seek);
    ;
    }
    else
    return;
    }

    void MainWindow::goal_seek()
    {
    double seek = 0;
    double goal = (ui->tableWidget_2->item(2,7)->text().toDouble());
    seekvalue (goal,1,6,seek);
    }
    @



  • Since your are calling update_output_table() in update_values(), directly and unconditionally, any call to update_values() will unavoidably call update_output_table(). Also, update_values() is called in seekvalue(), directly and unconditionally, so any call to seekvalue() will unavoidably call update_values(). Finally, seekvalue() is called in goal_seek(), directly and unconditionally, so any call to goal_seek() will unavoidably call seekvalue(). Consequently, when you are calling goal_seek() it means that update_output_table() will be called for sure.

    Anyway, I highly suggest you load your program into the Debugger and step trough the program line by line so you'll see what's happening...


Log in to reply