Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 83 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,89 @@ updating the typesystems as well.

# Building

## Building on Windows with MinGW
## General

To build PythonQt, you need to set the environment variable `PYTHON_PATH` to
point to the root dir of the python installation. Then you should set the
`PYTHON_VERSION` variable to the Python version number.
Building PythonQt requires a couple of steps.
Follow these instructions in order to get a correctly built PythonQt runtime and Qt bindings.

When using the prebuild Python installer, this will be:
### Recommendations

```cmd
set PYTHON_PATH=c:\Python310
set PYTHON_VERSION=3.10
```
It is recommended to build the Qt bindings yourself instead of using the pregenerated ones.
This ensures the bindings are compatible with your Qt version.
Do not build `PythonQt.pro` directly because it will only use the pregenerated bindings!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, it first checks for the path "generated_cpp", assuming that your self-generated sources are there, and only if it does not exist it checks for the other paths (see common.prf).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. No need to remove any pre-generated bindings. The generated_cpp will be used if created by user. I once tried to generate bindings and failed, so I've used 5.6 pre-gen bindings for a long time instead.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think it is a valid point - it is always preferrable to use the bindings generated for your concrete version instead of a pre-generated one for an older version. That generating the bindings did not work reliably before was one reason to use the pre-generated bindings that is now obsolete.
So maybe lessen the tone of the recommendation a bit ("It is recommended to build the Qt bindings yourself and not use the pregenerated ones."), and add a bit of a rational.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've lessen the tone.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not build PythonQt.pro directly because it will only use the pregenerated bindings!

This is partly true, in the sense that while it does build the generator first, it does not generate the bindings, so if you haven't built them before it will indeed use the checked-in ones.
I think you can leave it as is, but ultimately PythonQt.pro shall be adapted to also generate the bindings, maybe depending on some variable (or add the CMakeLists.txt files, or both).


### Environment

First, you need to set a couple of environment variables, which depend on your Python and Qt installation.

- `PYTHON_VERSION`

Set the version of your Python interpreter. The syntax is `<major>.<minor>`, e.g., `3.10`.

- `PYTHON_PATH`

This is the absolute path to the root directory of your Python installation.

- `PYTHON_LIB`

The absolute path to the `libs` directory in your python installation `$PYTHON_PATH/libs`.

- `PYTHON_DIR`

The `PYTHON_DIR` is required for non-Windows installations to find the `python-config` executable.
This should have the same value as `PYTHON_PATH`.

- `QTDIR`

The absolute path to the root directory of your Qt installation.

### Binding Generator

1. cd into the `generator` directory
2. Run qmake on `generator.pro`

`qmake CONFIG+=Release generator.pro`

3. Make the generator

Use `nmake` for MSVC (Visual Studio; make sure to have the environment variables set for Visual Studio beforehand). Otherwise, use `make`.

4. Generate the bindings

We use the generator executable from step 3 to generate the bindings.
The location of the generator executable can vary depending on your platform (the subdirectory is named after the current configuration, e.g., `release`).
On Windows, the generator is named `pythonqt_generator.exe`; on all other platforms, it is named `pythonqt_generator`.

`<generator-executable> qtscript_masterinclude.h build_all.txt`

### PythonQt Runtime

Next, we need the PythonQt runtime.

1. cd into the `src` directory
2. qmake `src.pro`

`qmake CONFIG+=Release src.pro`

3. Make the runtime

Use `nmake` for MSVC (Visual Studio; make sure to have the environment variables set for Visual Studio beforehand). Otherwise, use `make`.

### Extensions

As a last step, we need to build the extensions.

1. cd into `extensions`
2. qmake `src.pro`

`qmake CONFIG+=Release extensions.pro`

3. Make the extensions

Use `nmake` for MSVC (Visual Studio; make sure to have the environment variables set for Visual Studio beforehand). Otherwise, use `make`.

After all these steps, you should now have a fully working PythonQt runtime and Qt bindings for your Python/Qt installation 🎉.

## MinGW

It is possible to build PythonQt with MinGW on Windows instead of using MSVC.