Many QPushButtons clicked connecting using exec()

24 Views Asked by At

I have write this code:

    def top_music_clips(self,clips):
        try:
            self.top_20_clips = clips
            counter = 0
            for clip in self.top_20_clips:
                counter += 1
                exec("self.main_self.ui.music_clip_"+str(counter)+".clicked.connect(lambda state,clip_id="+str(clip["id"])+":self.top_clip_clicked(clip_id))")
                exec("self.main_self.ui.music_clip_"+str(counter)+".setText('"+str(clip["title"])+"')")
                exec("self.main_self.ui.music_clip_"+str(counter)+".setStyleSheet('QPushButton{font-size:7px;}')")
            #example for music_clip_1
            #self.main_self.ui.music_clip_1.clicked.connect(lambda state,clip_id=self.top_20_clips[0]["id"]:self.top_clip_clicked(clip_id))
        except:
            error_message = traceback.format_exc()
            self.main_self.open_music_clip_deck_error_window(error_message)

But when i push the button the program crashes. Note that the code in the comment work!

What's going wrong?

0

There are 0 best solutions below