pythonpyqtpyqt5qt-designeruic

Python & qtDesigner uic pop-up window lineEdit access


I'm newbie. I want to click a pushButton to open a new window and take text from main window lineEdit and copy to new pop-up window lineEdit.

So far I an create new window but can't access lineEdit. No errors, app is not responding.

This is what I have:

from PyQt5.QtWidgets import QApplication
from PyQt5 import uic

app = QApplication([]) #Main Window
ui = uic.loadUi(r"D:\UI_test\gui\main_gui_TT.ui")

appedit = QApplication([]) #Pop-up
uiedit = uic.loadUi(r"D:\UI_test\gui\input_TT.ui")

def edit1():
    uiedit.show()
    appedit.exec_()
    uiedit.lineEdit_CC.setText('text') <-this line is a problem


ui.pushButton_1edit.pressed.connect(edit1)
ui.show()
app.exec_()

Please help what is wrong here?


Solution

  • You should only have a single QApplication even if you have many windows, considering the above the solution is:

    from PyQt5.QtWidgets import QApplication
    from PyQt5 import uic
    
    app = QApplication([])  # Main Window
    ui = uic.loadUi(r"D:\UI_test\gui\main_gui_TT.ui")
    
    uiedit = uic.loadUi(r"D:\UI_test\gui\input_TT.ui")
    
    
    def edit1():
        uiedit.show()
        uiedit.lineEdit_CC.setText("text")
    
    
    ui.pushButton_1edit.pressed.connect(edit1)
    ui.show()
    app.exec_()