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

the line
app.exec_()
starts the event loop and you have two of those lines

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

But this made the ffriend display and exit immediately.

see this thread. It looks like the same issue.

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!

Guys, I am facing same issue, help me how you resolve this topic?

commented: See above solution for this problem. +0

I have the same problem , please help D:

I did this with qsystemtray and the context menu didn't work.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.