Q&A: QProcess.start() is deprecated, what are the alternatives?
Update how you launch subprocesses with arguments

A reader wrote in with an interesting problem when trying to launch an external script using QProcess.

When trying to launch another script in a sub-process I got the error: QProcess.start(const QString & command, QFlags<QIODevice::OpenModeFlag> mode) is deprecated. Having checked the documentation it mentioned .start() was obsolete but did not suggest replacement. Do you have any suggestions.

The confusion here comes from the .start() method being overloaded -- it can be called with different signatures (collections of arguments). The .start() method itself is not removed or deprecated, just the signature where .start() is called with a string containing the program and arguments together.

Deprecated members for QProcess List of deprecated methods for QProcess: note that only this signature for .start is deprecated

In the new API you need to instead set the program and arguments separately, with the latter passed as a list of strings -- one item per argument. This is a nicer way to do this -- less prone to errors since it's explicit what each thing you're passing actually is.

python
p = QProcess()
p.start("python dummy_script.py")
python
p = QProcess()
p.setProgram("python")
p.setArguments(['dummy_script.py'])
p.start()

The book has been updated with this new style API.

Create GUI Applications with Python & Qt6
The easy way to create desktop applications

My complete guide, updated for 2021 & PyQt6. Everything you need build real apps.

Downloadable ebook (PDF, ePub) & Complete Source code

To support developers in [[ countryRegion ]] I give a [[ localizedDiscount[couponCode] ]]% discount on all books and courses.

[[ activeDiscount.description ]] I'm giving a [[ activeDiscount.discount ]]% discount on all books and courses.

Continue reading

Introduction to the QGraphics framework  pyqt

The Qt Graphics View Framework allows you to develop fast and efficient 2D vector graphic scenes. Scenes can contain millions of items, each with their own features and behaviors. By using the Graphics View via PyQt you get access to this highly performant graphics layer in Python. Whether you're integrating … More