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. How to remove the mapper's item?
QtWS25 Last Chance

How to remove the mapper's item?

Scheduled Pinned Locked Moved Unsolved General and Desktop
qt guisignalmapper
5 Posts 3 Posters 1.7k 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.
  • Eng.JasonE Offline
    Eng.JasonE Offline
    Eng.Jason
    wrote on last edited by
    #1

    Hello, I used a QSignalMapper for used to lot of button clicked() event.

    unfortunately, i can't find, how to remove the QSignalMapper's item.

    So, I use QSignalMapper Iike this.

    ------------------------------------main.cpp-------------------------------
    // in main.cpp
    #define COUNT 7
    QSignalMapper *mapper = new SignalMapper();
    
    QList<QPushButton *> mButtons ;
    
    //setting
    for(int i =0; i < COUNT; i++)
    {
       QPushButton *pbtn = new QPushButton( );
       mButtons.append(pbtn);
       
      connect(mButtons[i], SIGNAL(clicked()), mapper, SLOT(map()));
      mapper->setMapping(mButton[i], i); 
    }
    RemoveMap(3);
    
    -----------------------------------------------------------------------------
    
    void myclass::RemoveMap(int index)
    {
     // I want to know, how to remove mapper's item by index parameter.
     // I saw the removeMappings( ) function, but I couldn't guess the how to use it;..
    }
    
    I need your help. thank you.
    
    kshegunovK 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Something like mapper->removeMapping(myButton[i]);

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      3
      • Eng.JasonE Eng.Jason

        Hello, I used a QSignalMapper for used to lot of button clicked() event.

        unfortunately, i can't find, how to remove the QSignalMapper's item.

        So, I use QSignalMapper Iike this.

        ------------------------------------main.cpp-------------------------------
        // in main.cpp
        #define COUNT 7
        QSignalMapper *mapper = new SignalMapper();
        
        QList<QPushButton *> mButtons ;
        
        //setting
        for(int i =0; i < COUNT; i++)
        {
           QPushButton *pbtn = new QPushButton( );
           mButtons.append(pbtn);
           
          connect(mButtons[i], SIGNAL(clicked()), mapper, SLOT(map()));
          mapper->setMapping(mButton[i], i); 
        }
        RemoveMap(3);
        
        -----------------------------------------------------------------------------
        
        void myclass::RemoveMap(int index)
        {
         // I want to know, how to remove mapper's item by index parameter.
         // I saw the removeMappings( ) function, but I couldn't guess the how to use it;..
        }
        
        I need your help. thank you.
        
        kshegunovK Offline
        kshegunovK Offline
        kshegunov
        Moderators
        wrote on last edited by kshegunov
        #3

        @Eng.Jason
        To add to @SGaist, you seem to be using one mapper with multiple buttons, which will not work. A signal mapper will map a single signal, from a single object.

        EDIT: Disregard this completely wrong comment.

        Read and abide by the Qt Code of Conduct

        1 Reply Last reply
        1
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @kshegunov Why will it not work ? AFAIK that's the goal of QSignalMapper: to map several objects to one signal with a parameter of known value.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          kshegunovK 1 Reply Last reply
          0
          • SGaistS SGaist

            @kshegunov Why will it not work ? AFAIK that's the goal of QSignalMapper: to map several objects to one signal with a parameter of known value.

            kshegunovK Offline
            kshegunovK Offline
            kshegunov
            Moderators
            wrote on last edited by kshegunov
            #5

            @SGaist said:

            Why will it not work ? AFAIK that's the goal of QSignalMapper: to map several objects to one signal with a parameter of known value.

            I seem to have missed my morning coffee when I wrote that. Sure it will work.

            Read and abide by the Qt Code of Conduct

            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