Using a slot without firing a signal from that function?



  • I am trying to implement something in my program where the user inputs a number into a QLineEdit box that specifies a frame buffer size. Once they hit Enter or leave the box, the program checks if previous frame buffer has been saved before resizing to the new value. This is done by checking for editingFinished(). That signal is connected to the function that asks the user whether they want to save the old data, discard it, or "cancel" and pretend they never tried to change anything. But the text is already changed in the QLineEdit box and I want to revert it to what it was previously. I have that previous value stored already and wanted to just use setText() to the old value if the user hits "cancel" and then exit out of the function entirely. However, when I use setText(), it fires off editingFinished() again, basically starting an infinite loop if I keep hitting "cancel". Is there any way to set the text in the QLineEdit box without firing off editingFinished()?

    My current solution is very inelegant. I basically have a variable I keep track of. If the user hits "cancel", the variable gets flipped to TRUE and when the program tries to go back to the same function again, it just skips over the whole thing. Basically:

    @if(!var)
    {
    //switch statement
    case "cancel":
    var = TRUE;
    ui->lineEdit.setText("blah");
    return;
    }else
    {
    var = FALSE;
    }@

    So the code goes into the "cancel" section of the switch statement, sets var to TRUE, fires off editingFinished(), which makes the code go to the function again, but this time sees var = TRUE, so it goes to the other part of the if/else and just resets var.

    This happens very fast and all, but I can't help but feel it's a poor solution and there should be a better one out there.

    Help? :(


  • Moderators

    Did you see that there is an "undo functionality":http://doc.qt.nokia.com/4.7/qlineedit.html#undo available?
    That seems to be what you are looking for. Unfortunately there is not a lot of documentation, what is really does.


Log in to reply
 

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