This is a "Proof of concept" of a QT binding for PHP 8+.
This is a PHP extension developed in C++ and currently tested on MacOS and Linux. Since PHP doesn't support C++ and the extension development process has very limited documentation, I've used PHP-CPP library to develop this POC. You can run the following commands to compile PHP-CPP,
git clone https://github.com/CopernicaMarketingSoftware/PHP-CPP.git
cd PHP-CPP
git checkout master
make && sudo make install
This will clone, compile & install PHP-CPP in your system. You will also need make
and g++
commands installed.
Now before you compile this extension, you need to install qt6
and headers. This can be done with,
brew install qt@6
# OR for arch-based distro
sudo pacman -S qt6-base
Go ahead and compile this repo,
git clone https://github.com/nazmulpcc/phpqt.git
cd phpqt
make && sudo make install
This will compile the extension to a file called phpqt.so and put it in php's extension directory (php-config --extension-dir
). This will also create a ini file called phpqt.ini
(which loads the extension). If for some reason the Makefile cannot put these files in the correct location, you can manually copy them to the right location.
Once installed, you can see which classes and methods are available from here. A demo using this extension is available here.
- In some cases, automatic extension installation fails, if that happens to you, you can put the
.so
and.ini
files in the correct location manually. - In my experiments, the extension is very stable on MacOS (M1). In linux, it crashes 1 out of 4 times. This used to be a lot worse but improved gradually.
- Only a handful of classes from the QT framework have been ported to PHP since this is just a Proof of concept.
- In some cases, using multiple threads via the
Thread
classes causes memory error.
Why not? PHP is a very matured language and you can do some wild things with PHP. You can create a websocket server, machine learning, high performance async IO library, proxy server, async imap client and many many more. So why not a native desktop application?
This POC was created because I wanted to create a few small gui workflows and I did not want to use electron or another JS based solution. If I find sufficient interest from the PHP community or I need this myself in the future, I will continue investing time and see what it becomes. Personally, I beleive there is a lot of potential here as PHP is very easy to learn, fun to work with and it has a HUGE eco system. For me, I will probably implement things like, printing support, a few more widget classes, bluetooth connectivity, qt's network module etc.