Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Too many connections to slots?
Qt 6.12 LTS is out! See what's new in the release blog

Too many connections to slots?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.1k 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.
  • C Offline
    C Offline
    cuddlykittens11
    wrote on last edited by
    #1

    I just got done making a small color choosing widget. I added some print statements into the slots to see of often they were being called. I noticed that even if I only move one slider/spinner, the same slot may be called more than once. This may be beucase I'm using the setValue() funciton which should emit a signal.

    The code is below (in Python and PyQt), but I'm wondering if this is fine, or if I should try to find some way to make sure a slot is only called once during "one," event.

    The code is too big to post, "So here's a link":https://gist.github.com/define-private-public/8f58bf81f78907b56d31.

    1 Reply Last reply
    0
    • T Offline
      T Offline
      thoughthorizon
      wrote on last edited by
      #2

      You definitely have a circular signal/slot connection going on there - setValue() on the spin box emits valueChanged() which invokes setValue() on the slider which emits a valueChanged() which invokes setValue() on the spin box, and so on.

      However, functions like "setValue()" on widgets have an emit policy which is usually only to emit if the value is changed.

      So if we setValue(X) our spinbox (hence emitting a signal) which calls setValue(X) on our slider (which emits a signal) which then calls setValue(X) on our spinbox, we don't get a signal from this final setValue() as the value has not changed - it has been set from X to X. So you might be calling the setValue slot a couple of times whenever you change a value.

      To summarise, then, setValue only emits a valueChanged if the new value is different from the previous value, so your code is fine.

      1 Reply Last reply
      0
      • C Offline
        C Offline
        cuddlykittens11
        wrote on last edited by
        #3

        Okay, I'm trying to avoid an ifinite loop or something along those lines. I think it is possible to make it so that only one slot/signal get called/sent, but it looks like this is fine as is.

        Thanks for the reasurance.

        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
        • Unsolved