0

I've been searching for this issue on the internet, but I didn't found an answer. My problem is that I am creating multiple QAction that I store in a list, but I can't seem to connect them with their triggered slot:

    def refresh_research_menu(self):
        self.action_research = []
        self.action_research.append(qtw.QAction("Research", self))
        self.action_research[-1].setShortcut("Ctrl+R")
        self.action_research[-1].triggered.connect(self.get_research)
        for mat in myList:
            self.action_research.append(qtw.QAction(mat))
            self.action_research[1].triggered.connect(lambda : self.mySlot(MyList[1])) #Problem here
            myMenu[1].addAction(self.action_research[-1])

Now, when I compile my code, I only get the last iteration (myList[-1]), so each action of the menu is connected to self.mySlot(myList[-1]) which is my issue. Thanks!

Wievers
  • 1
  • 1
  • `for mat in myList: action = qtw.QAction(mat) action.triggered.connect(lambda checked, v=mat: self.mySlot(v)) myMenu[1].addAction(action) elf.action_research.append(action)` – eyllanesc Jun 03 '20 at 12:39
  • Thanks! I didn't find the answer before. I guess I didn't serach the right key words... – Wievers Jun 03 '20 at 12:42

0 Answers0