Hi all,

I have 2 form and a main.py in the project: ffrend.py and fmain.py

main.py:

from PyQt4 import QtCore, QtGui
from fmain import *

if __name__ == "__main__":
    import sys
    app = QtGui.QApplication(sys.argv)
    MainWindow = QtGui.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    app.exec_()

fmain.py (there is a button to execute the following function)

def friendNetWork(self):
        form = QtGui.QWidget()
        ui = Ui_ffriend()
        ui.setupUi(form)
        form.show()
        app.exec_()

When I run main.py, the fmain form is shown. When I click the button on fmain form, the friendNetWork will be executed and create another widget.

But...I received the error in console :(...And the python is hang :(

QCoreApplication::exec: The event loop is already running
QCoreApplication::exec: The event loop is already running
QCoreApplication::exec: The event loop is already running
QCoreApplication::exec: The event loop is already running

Please help me with this

Actually, I tried to remove app.exec_() in the friendNetWork function.

But this made the ffriend display and exit immediately.

Hi Gribouillis,

Thanks for your reply.

I changed my solution a litte bit:

  • Create a reference for ffriend in fmain
  • Remove app.exec_() in ffriend

Now the ffriend can be displayed without app.exec_().

But another problem occured, I can't interact with ffriend. There is a button on ffriend will do something as printing a message. Now, I clicked the button but nothing printed :'(

def setupUi(self, ffriend):
    ### Code generated from Pyuic
    ...
    self.btnphantich = QtGui.QPushButton(ffriend)
    ...
    QtCore.QObject.connect(self.btnphantich, QtCore.SIGNAL(_fromUtf8("clicked()")), self.printhello)
    QtCore.QMetaObject.connectSlotsByName(ffriend)

def printhello(self):
    print "hello world!" ### No hello world here although it can be printed with app.exec_()

Please gui me or point me what to read next.

Thank you!

This question has already been answered. Start a new discussion instead.