I'm coding an application to run when starting raspberry, however when trying to run this error is returned:

QXcbConnection: Could not connect to display

My application is done in python with qt interface, when I put only print("test") the application runs. How do I correct this? The raspberry is configured in console mode

  • How do you intend to run a graphical application in console mode? – crasic Mar 16 '19 at 19:19
  • You can't start GUI programs from cron or from /etc/rc.local Those both run too early. – Dougie Mar 16 '19 at 19:23
  • Please take note that using /etc/rc.local has limitations due to Compatibility with SysV. We have seen many problems here on this site using it. Following the recommendation of the developers from systemd you should avoid using it. – Ingo Mar 19 '19 at 9:58

If you want to use QT utility libraries but not the GUI library, you must selectively import only the library components that you need to use. By importing the root PyQT package you are setting up the draw thread of the QT system, which requires a display connection.

  • I'm importing like this: from PyQt5 import uic, QtCore, QtGui, QtWidget I'm trying to display an application with Qt graphical interface, display a window with raspberry in console mode. – kenta Mar 16 '19 at 19:46
  • I will refer to my original comment, how do you intend to display a window in console mode ? How would this work ? All of the QtGui and QtWidget requir a display connection and a logged in graphical user – crasic Mar 16 '19 at 19:47
  • How can I run my application by turning on raspberry without the user seeing the desktop? – kenta Mar 16 '19 at 20:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.