Error "QWidget: Must construct a QApplication..." with flowcharts

3,253 views
Skip to first unread message

michael.m...@gmail.com

unread,
Sep 29, 2013, 5:55:20 AM9/29/13
to pyqt...@googlegroups.com
Hello,

I am interested in PyQtGraph's flowchart feature and wanted to try it on my system (Linux Mint 15).
I installed the Deb package from the website (python-pyqtgraph_0.9.7-1_all.deb).

I copy-pasted in the Python console the first flowchart example from the documentation ( http://www.pyqtgraph.org/documentation/flowchart/index.html ):
from pyqtgraph.flowchart import Flowchart
fc = Flowchart(terminals={
    'nameOfInputTerminal': {'io': 'in'},
    'nameOfOutputTerminal': {'io': 'out'}
})

And I get the following error after confirming the second line:
QWidget: Must construct a QApplication before a QPaintDevice

Any idea on how this can be fixed ?

Thank you for your help !
M. Mestre

Guillaume Poulin

unread,
Sep 29, 2013, 6:47:30 AM9/29/13
to pyqt...@googlegroups.com
 That's come from PyQt. Before creating any QWidget (PyQtGraph create many QWidget), you need to create to a QApplication and start the Qt event loop. This can be done by calling 
app=QtGui.QApplication([])
app
.exec_()
This generally go in the "if __name__ == '__main__':" part of your python script. Be careful, creating two QApplication result in an Segfault. You can test if there is a QAppliction running with QtGui.QApplication.instance()

If you want to work in an interactive python console I suggest you to use IPython and to launch it with `ipython --pylab=qt`. IPython gonna take care to create the QApplication and gonna handle the Qt even loop.

I suggest you to look at a PyQt tutorial for more details.

Guillaume Poulin

unread,
Sep 29, 2013, 6:53:17 AM9/29/13
to pyqt...@googlegroups.com
Le dimanche 29 septembre 2013 18:47:30 UTC+8, Guillaume Poulin a écrit :
Le dimanche 29 septembre 2013 17:55:20 UTC+8, michael.m...@gmail.com a écrit :
Hello,

I am interested in PyQtGraph's flowchart feature and wanted to try it on my system (Linux Mint 15).
I installed the Deb package from the website (python-pyqtgraph_0.9.7-1_all.deb).

I copy-pasted in the Python console the first flowchart example from the documentation ( http://www.pyqtgraph.org/documentation/flowchart/index.html ):
from pyqtgraph.flowchart import Flowchart
fc = Flowchart(terminals={
    'nameOfInputTerminal': {'io': 'in'},
    'nameOfOutputTerminal': {'io': 'out'}
})

And I get the following error after confirming the second line:
QWidget: Must construct a QApplication before a QPaintDevice

Any idea on how this can be fixed ?

Thank you for your help !
M. Mestre

 That's come from PyQt. Before creating any QWidget (PyQtGraph create many QWidget), you need to create to a QApplication and start the Qt event loop.

In fact, you don't need a Qt event loop to create a QWidget but you are gonna need it for a lot of other things (like interacting with your graph).

michael.m...@gmail.com

unread,
Sep 29, 2013, 6:55:23 AM9/29/13
to pyqt...@googlegroups.com
Yup, it works :)

Thank you very much for your help !!
Are there any simple examples online for a minimal working program implementing flowcharts ?

Best regards,
Michael

Guillaume Poulin

unread,
Sep 29, 2013, 7:08:22 AM9/29/13
to pyqt...@googlegroups.com
Le dimanche 29 septembre 2013 18:55:23 UTC+8, michael.m...@gmail.com a écrit :
Yup, it works :)

Thank you very much for your help !!
Are there any simple examples online for a minimal working program implementing flowcharts ?

Best regards,
Michael

Did you have a look at 'examples/Flowchart.py' and 'examples/FlowchartCustomNode.py' included with PyQtGraph?

michael.m...@gmail.com

unread,
Sep 29, 2013, 7:43:54 AM9/29/13
to pyqt...@googlegroups.com
Perfect, thank you !!!



On Sunday, September 29, 2013 11:55:20 AM UTC+2, michael.m...@gmail.com wrote:
Reply all
Reply to author
Forward
0 new messages