I’ve been playing with Qt4 today, the main C++ version, not the PyQt3 Python wrapper I’ve used before.
I’ve noticed that the code is very similar, pretty much the same number of lines of code for a “Hello World!” windowed application. I had my suspicions before, as the PyQt syntax doesn’t seem very Pythonic.
It doesn’t really bode well for Python as a rapid application development environment for Qt programs if you can do the same in C++ without the extra overhead of an interpreter, with the same amount of effort (if you use QtDesigner, there’s probably even less difference). The only reasons I can see the point of using PyQt is less recompiling whilst testing, and if you want a built-in scripting shell.
Python Qt3:
1 2 3 4 5 6 7 8 9 10 11 | #!/bin/env python import sys from qt import * app = QApplication(sys.argv) mainwindow = QMainWindow() button = QPushButton("Quit", mainwindow) app.connect(button, SIGNAL("clicked()"), app, SLOT("quit()")) mainwindow.show() app.exec_loop() |
C++ Qt4:
1 2 3 4 5 6 7 8 9 10 11 | #include <QApplication> #include <QPushButton> int main(int argc, char *argv[]) { QApplication app(argc, argv); QPushButton *button = new QPushButton("Quit"); QObject::connect(button, SIGNAL(clicked()), &app, SLOT(quit())); button->show(); return app.exec(); } |