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. Using a slot without firing a signal from that function?
Qt 6.11 is out! See what's new in the release blog

Using a slot without firing a signal from that function?

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.9k Views 1 Watching
  • 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.
  • W Offline
    W Offline
    WarPhalange
    wrote on last edited by
    #1

    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? :(

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      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.

      Vote the answer(s) that helped you to solve your issue(s)

      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