Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

how to show the ui and then run a loop?



  • Hi!

    I want to make a loop that analyzes files

    Inside each iteration I want to log stuff in the ui

    The problem is that I don't know where to put the loop in the code

    Doesn't matter where i put it, when I run the code always starts the loop and then shows the ui

    But I want the reverse: to see the ui first, and then see the loop logging in the ui

    This is the bulk of the ui code, where i should put the loop?:

    *lots of imports*
    *lots of imports*
    *lots of imports*
    
    class MainWindow(QMainWindow):
        def __init__(self):
            QMainWindow.__init__(self)
            self.ui = Ui_MainWindow()
            self.ui.setupUi(self)
            ...
            ...
            ...
    
    if __name__ == "__main__":
        app = QApplication(sys.argv)
        window = MainWindow()
        window.show()
        sys.exit(app.exec_())
    

    the simplified loop looks something like this:

    for each_file in files:
        log(each_file)
    

    Thanks!


  • Lifetime Qt Champion

    Hi,

    If you want to do heavy processing you should consider using QtConcurrent to avoid blocking your GUI


  • Lifetime Qt Champion

    Hi,

    If you want to do heavy processing you should consider using QtConcurrent to avoid blocking your GUI



  • @SGaist Thanks! I will read about that



  • @SGaist So you were suggesting multiprocessing? That makes sense
    I know how to do that with the standard module in python: threading
    That should work too?
    I'm not that experienced in programming and I don't know if using the module(I guess it's called module) QtConcurrent from Qt its obligatory or not, it is?


  • Lifetime Qt Champion

    It's not obligatory but it will be better integrated and also easier to get you started since as you wrote you are new to programming.



  • @SGaist Thanks a lot!


Log in to reply