I have software which has a GUI interface and a command line interface. What it should do is detect if it is being run in a qtconsole. If it is, it will not create a new QApplication and show the GUI in a non-blocking manner. After the script exists, there will be a cmd object where the user can interact with things on a lower level.
from PyQt4.QtCore import QCoreApplication
from PyQt4.Qt import QApplication
import sys
QApp = QCoreApplication.instance()
new_qapp_bit = False
if QApp == None:
print 'running without the qt console'
new_qapp_bit = True
QApp = QApplication(sys.argv)
else:
print 'found the qt console'
cmd = MyCMDInterface(use_gui=True)
if new_qapp_bit
sys.exit(QApp.exec_())
On windows this works perfectly, QCoreApplication.instance() returns a valid QApplication and everything goes according to plan, but on Linux and Mac it returns None. I've been hacking at this awhile, and I'm not seeing any answers.
The problem was I forgot the '--pylab=qt ' argument when I ran
ipython qtconsole --pylab=qt --color=Linux -c "%run main.py"