Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Slot function not updating when not called from MainWindow function

Slot function not updating when not called from MainWindow function

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 1.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DeanQt
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MuldeR
      wrote on last edited by
      #2

      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?

      My OpenSource software at: http://muldersoft.com/

      Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

      Go visit the coop: http://youtu.be/Jay...

      1 Reply Last reply
      0
      • D Offline
        D Offline
        DeanQt
        wrote on last edited by
        #3

        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...

        1 Reply Last reply
        0
        • M Offline
          M Offline
          MuldeR
          wrote on last edited by
          #4

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

          My OpenSource software at: http://muldersoft.com/

          Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

          Go visit the coop: http://youtu.be/Jay...

          1 Reply Last reply
          0
          • D Offline
            D Offline
            DeanQt
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • JKSHJ Offline
              JKSHJ Offline
              JKSH
              Moderators
              wrote on last edited by
              #6

              [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.

              Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

              1 Reply Last reply
              0
              • D Offline
                D Offline
                DeanQt
                wrote on last edited by
                #7

                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);
                }
                @

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  MuldeR
                  wrote on last edited by
                  #8

                  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...

                  My OpenSource software at: http://muldersoft.com/

                  Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

                  Go visit the coop: http://youtu.be/Jay...

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved