0

In I my attempts at creating a GUI (a document viewer) with PyQt4, failing reproduce the quality of existing programs, it has been suggested I should use those existing program's Qt4 Widgets (Okular's to be precise), rather than re-inventing the wheel.

Fair enough, but those Qt4 widgets are written in C++: how am I supposed to call them from the Python side? And does it require me to learn C (in which case I'd rather put more time in figuring out a fully Pythonic solution)?

1
  • Corrected questions as Mata pointed out Qt is written in C++, and not C as I first had assumed. Commented May 23, 2012 at 21:28

1 Answer 1

1

Qt isn't written in C, its's written in C++, and so is Okular.

Unfortunately getting C++ libraries to work with python is not as easy as using C libraries through ctypes. To do that, you'll need to write some wrapper code around the C++ APIs to get it working.
Some ways to do that:

  • sip - used by PyQt
  • shiboken - used by PySide
  • cython can also be used to wrap C++, don't know if it plays well with Qt
Sign up to request clarification or add additional context in comments.

2 Comments

OK. So supposing I need a module from Okular, say a PDFViewer widget, I can simply follow the C++ example on the SIP documentation. Then after creating those scripts, I could simply import the modules and their class as if those were written in Python? It sounds too good to be true.
yes, however you'll still have to write all the sip definition code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.