[Qt-creator] Dealing with python projects

Christian Kandeler Christian.Kandeler at qt.io
Wed Apr 24 09:20:35 CEST 2019


On Wed, 24 Apr 2019 12:49:19 +1200
Christian Gagneraud <chgans at gmail.com> wrote:

> So I recently switched to using Qbs. It currently allows me to
> organise my python files, and QtCreator is happy with this "broken"
> qbs project (broken=cannot be built).
> One interesting feature is that i can configure QtC to run the test
> webserver using a simple wrapper script. And with a project type of
> "python" (or whatever is not recognised by qbs) QtC skip the build
> process.

I don't think you need to do that. If there's no cpp sources or libraries around, the build process is a no-op for an Application as well.
By the way, if your main python file has a shebang at the top, you can get a run configuration for it by simply tagging it as an application. (It involves a copy because source artifacts cannot be target artifacts in qbs atm, but that's not a limitation in practice).
For instance:

-----
import qbs.File

Application {
    Group {
        name: "main script"
        files: "pythontest.py"
        fileTags: "python"
    }
    Rule {
        inputs: "python"
        Artifact {
            filePath: input.baseName + "-exe.py"
            fileTags: "application"
        }
        prepare: {
            var cmd = new JavaScriptCommand();
            cmd.description = "creating " + output.fileName;
            cmd.sourceCode = function() { File.copy(input.filePath, output.filePath); };
            return cmd;
        }
    }
}
-----

If you open this project in Qt Creator, Ctrl+R will run your python script.


Christian


More information about the Qt-creator mailing list