简体   繁体   中英

How to increment QLineEdit name to access value?

This seems like a really simple question, but has me stumped. I've got a UI that has multiple QLineEdits for names, start, and end times. For example:

clipName1, clipStart1, clipEnd1 clipName2, clipStart2, clipEnd2 clipName2, clipStart3, clipEnd3

These are not dynamically built on the fly. They are static. I wish to access the values from these by going through a loop. I am not sure how I can append an integer onto the variable name and still be able to access the value. I've tried this which I know doesn't work:

    clipTotal = 4

    for i in range(1, clipTotal+1):
        clipName = self.clipName+str(i)+.text()

Answer provided by ekhumoro in comments above:

clipName = getattr(self, 'clipName%d' % i).text()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM