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. Qt Shortcut Keys activated signals
QtWS25 Last Chance

Qt Shortcut Keys activated signals

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

    I noticed that my code as shown below executes the slot function twice. So the integer being changed either has 1 added twice or subtracted twice. Is this intended or is there a way around this?

      QShortcut *add= new QShortcut(Qt::Key_Plus, this);
      QShortcut *sub= new QShortcut(Qt::Key_hyphen this);
    
      QSignalMapper *mapper = new QSignalMapper(this);
      QObject::connect(next, SIGNAL(activated()), mapper, SLOT(map()));
      QObject::connect(prev, SIGNAL(activated()), mapper, SLOT(map()));
    
      mapper->setMapping(next, 1);
      mapper->setMapping(prev, -1);
    
      QObject::connect(mapper, SIGNAL(mapped(int)), this, SLOT(increment(int)));
      QObject::connect(mapper, SIGNAL(mapped(int)), this, SLOT(increment(int)));
    
    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      Ï think the double issue comes from this

      QObject::connect(mapper, SIGNAL(mapped(int)), this, SLOT(increment(int)));
      QObject::connect(mapper, SIGNAL(mapped(int)), this, SLOT(increment(int)));

      That would fire it twice for an int since they are 100% identical.

      Akito_KamiA 1 Reply Last reply
      2
      • Venkatesh VV Offline
        Venkatesh VV Offline
        Venkatesh V
        wrote on last edited by
        #3

        Hi @Akito_Kami ...

        try using Qt::UniqueConnection in connect statement... hope problem gets resolved.

        1 Reply Last reply
        0
        • mrjjM mrjj

          Hi
          Ï think the double issue comes from this

          QObject::connect(mapper, SIGNAL(mapped(int)), this, SLOT(increment(int)));
          QObject::connect(mapper, SIGNAL(mapped(int)), this, SLOT(increment(int)));

          That would fire it twice for an int since they are 100% identical.

          Akito_KamiA Offline
          Akito_KamiA Offline
          Akito_Kami
          wrote on last edited by
          #4

          @mrjj Thanks. Removing one of the statements worked.

          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