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. QCompleter sets text after activated signal
QtWS25 Last Chance

QCompleter sets text after activated signal

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 1.2k 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.
  • JonBJ Offline
    JonBJ Offline
    JonB
    wrote on last edited by JonB
    #1

    I have a QLineEdit with a QCompleter. I act on the content immediately when it is completed. But then the requirement is to empty the QLineEdit text.

    When the user types and presses Return I get the QLineEdit::editingFinished signal, deal with the content, and clear it out --- no problem.

    When the user clicks a selection from the QCompleter I get the QCompleter::activated signal. I can do what I like in that --- act on the content directly, or emit() the QLineEdit::editingFinished signal which is what I actually do. I finish of by clearing the text in this slot, or whatever that calls, as above.

    The problem is that after QCompleter::activated signal slots have completed and returned, something in the Qt framework is then setting the attached QLineEdit text to what the user chose. I can see a QLineEdit::textChanged() signal for that. This means that my attempts to clear the line edit are to no avail, it gets to set to what the user selected by Qt later on.

    Is there anything I can do about this? Otherwise I'm going to have a place a timer in QCompleter::activated slot to clear the text later....

    J.HilkJ 1 Reply Last reply
    0
    • JonBJ JonB

      I have a QLineEdit with a QCompleter. I act on the content immediately when it is completed. But then the requirement is to empty the QLineEdit text.

      When the user types and presses Return I get the QLineEdit::editingFinished signal, deal with the content, and clear it out --- no problem.

      When the user clicks a selection from the QCompleter I get the QCompleter::activated signal. I can do what I like in that --- act on the content directly, or emit() the QLineEdit::editingFinished signal which is what I actually do. I finish of by clearing the text in this slot, or whatever that calls, as above.

      The problem is that after QCompleter::activated signal slots have completed and returned, something in the Qt framework is then setting the attached QLineEdit text to what the user chose. I can see a QLineEdit::textChanged() signal for that. This means that my attempts to clear the line edit are to no avail, it gets to set to what the user selected by Qt later on.

      Is there anything I can do about this? Otherwise I'm going to have a place a timer in QCompleter::activated slot to clear the text later....

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @JonB a real quick, and possibly dirty, workaround would be to connect your QCompleter::activated signal to your slot via a Qt::QueuedConnection


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      JonBJ 1 Reply Last reply
      2
      • J.HilkJ J.Hilk

        @JonB a real quick, and possibly dirty, workaround would be to connect your QCompleter::activated signal to your slot via a Qt::QueuedConnection

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #3

        @J.Hilk
        Thanks. About to try now. Never used one of those so I have to figure the syntax in PyQt first!

        I need the Qt internal code which raises the signal to finish off its internal populating of the line edit first. Is that what QueuedConnection does? So it pushes its intended raised signal to a queue, then completes its own stuff, and I guess hits the event lop which then raises the signal. Is that the gist?

        J.HilkJ 1 Reply Last reply
        0
        • JonBJ JonB

          @J.Hilk
          Thanks. About to try now. Never used one of those so I have to figure the syntax in PyQt first!

          I need the Qt internal code which raises the signal to finish off its internal populating of the line edit first. Is that what QueuedConnection does? So it pushes its intended raised signal to a queue, then completes its own stuff, and I guess hits the event lop which then raises the signal. Is that the gist?

          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          @JonB said in QCompleter sets text after activated signal:

          I need the Qt internal code which raises the signal to finish off its internal populating of the line edit first. Is that what QueuedConnection does? So it pushes its intended raised signal to a queue, then completes its own stuff, and I guess hits the event lop which then raises the signal. Is that the gist?

          In essence yes.

          Normally all connect() are done with AutoConnect (it's the default value, when not specified). When signal and slot life in the same thread then that is a DirectConnect.

          Meaning the slot is executed directly when the signal is emitted. If multiple slots are connected to the same signal, than they are executed one after the other, in order of the initial connect calls.

          By forcing a QueuedConnection the slot is not executed but queued to be executed first thing, next event loop cycle.

          In this case, it will have the same effect as a SingleShot timer with a timeout of 0


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          JonBJ 1 Reply Last reply
          1
          • J.HilkJ J.Hilk

            @JonB said in QCompleter sets text after activated signal:

            I need the Qt internal code which raises the signal to finish off its internal populating of the line edit first. Is that what QueuedConnection does? So it pushes its intended raised signal to a queue, then completes its own stuff, and I guess hits the event lop which then raises the signal. Is that the gist?

            In essence yes.

            Normally all connect() are done with AutoConnect (it's the default value, when not specified). When signal and slot life in the same thread then that is a DirectConnect.

            Meaning the slot is executed directly when the signal is emitted. If multiple slots are connected to the same signal, than they are executed one after the other, in order of the initial connect calls.

            By forcing a QueuedConnection the slot is not executed but queued to be executed first thing, next event loop cycle.

            In this case, it will have the same effect as a SingleShot timer with a timeout of 0

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #5

            @J.Hilk
            Your QueuedConnection does the job for me. Thanks :)

            1 Reply Last reply
            1

            • Login

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