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. qsignalmapper change object
Forum Updated to NodeBB v4.3 + New Features

qsignalmapper change object

Scheduled Pinned Locked Moved Solved General and Desktop
qsignalmapper
6 Posts 3 Posters 2.4k 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.
  • G Offline
    G Offline
    gatz
    wrote on last edited by gatz
    #1

    Hello,

    I have a couple of buttons connected to a signal mapper and I would like to change the object an update.

    ...
    signalMapper = new QSignalMapper(this);
    connect(signalMapper, SIGNAL(mapped(QObject*)), this, SLOT(on_delete_clicked(QObject*)));
    
    QPushButton *deleteButton = new QPushButton("x");
    deleteButton->setObjectName("delButton1");
    signalMapper->setMapping(deleteButton, obj);
    connect(deleteButton, SIGNAL(clicked()), signalMapper, SLOT(map()));
    layout->addWidget(deleteButton);
    ....
    

    I tried to get the button, set the mapping (hopping that will overwrite it) and connecting the button to the signal mapper again, but no luck; I'm still getting the old object. "deleteButton" is found.

    QPushButton *deleteButton = ui->mainbox_scrollArea->findChild<QPushButton *>("delButton1");
    if (deleteButton) {
         signalMapper->setMapping(deleteButton, obj);
         connect(deleteButton, SIGNAL(clicked()), signalMapper, SLOT(map()));
    }
    

    There is any way to do this?
    Thanks

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

      Hi,

      Can you explain what exactly you are trying to achieve ?

      Because the deleteButton you get from that findChild call will be exactly the same you put there at the first place (at least from the code you gave).

      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
      0
      • G Offline
        G Offline
        gatz
        wrote on last edited by gatz
        #3

        I have a list of QHBoxLayout and each of them contains a delete button, edit button and a label.
        For each button I map an object with information (title, description, ids, cat, etc) and I connect it to a signal mapper.
        On edit button I open a new window, edit the information and send the new object to the MainWindow. Up to here everything works fine.
        Then I want to update the object data from those buttons, so on the next edit or delete to show me the updated information and not the old information before the update. That's the reason I am getting the same button and trying to map the new object on it, hopping it will overwrite it.

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

          Aren't recreating some sort of QListWidget ?

          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
          0
          • hskoglundH Offline
            hskoglundH Offline
            hskoglund
            wrote on last edited by
            #5

            Hi, perhaps your second call to ->setMapping() is rejected (i.e. your overwrite is refused) because the docs say "There may be at most one object for each sender".
            Try calling removeMappings() or maybe easier, consider creating a new QSignalMapper object.

            G 1 Reply Last reply
            1
            • hskoglundH hskoglund

              Hi, perhaps your second call to ->setMapping() is rejected (i.e. your overwrite is refused) because the docs say "There may be at most one object for each sender".
              Try calling removeMappings() or maybe easier, consider creating a new QSignalMapper object.

              G Offline
              G Offline
              gatz
              wrote on last edited by gatz
              #6

              @hskoglund calling removeMappings() and then setMapping seems to work. Thanks

              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