python generator missing in uic while trying to convert .ui file to .py

463 views Asked by At

I'm trying to convert a .ui file into a python file using uic file.ui -o file.py and other combinations of that, but even though the generated file is a .py file, the code that's in it is c++. After some googling and researching some uic prefixes I noticed that in my uic --help menu I only have java and cpp generators, but in every tutorial ppl have python|cpp generators. enter image description here

What might be the reason for that and how can that be fixed?

2

There are 2 answers

0
eyllanesc On BEST ANSWER

The generator for python has been introduced in the latest versions of Qt so it is probably not available in your 5.9.7 version of Qt, so you will have to install a more recent version, for example in my case I use version 5.15.2:

Usage: uic [options] [uifile]
Qt User Interface Compiler version 5.15.2

Options:
  -h, --help                    Displays help on commandline options.
  --help-all                    Displays help including Qt specific options.
  -v, --version                 Displays version information.
  -d, --dependencies            Display the dependencies.
  -o, --output <file>           Place the output into <file>
  -a, --no-autoconnection       Do not generate a call to
                                QObject::connectSlotsByName().
  -p, --no-protection           Disable header protection.
  -n, --no-implicit-includes    Disable generation of #include-directives.
  -s, --no-stringliteral        Deprecated. The use of this option won't take
                                any effect.
  --postfix <postfix>           Postfix to add to all generated classnames.
  --tr, --translate <function>  Use <function> for i18n.
  --include <include-file>      Add #include <include-file> to <file>.
  -g, --generator <python|cpp>  Select generator.
  --idbased                     Use id based function for i18n
  --from-imports                Python: generate imports relative to '.'

Arguments:
  [uifile]                      Input file (*.ui), otherwise stdin.

so now I can convert the .ui to .py by running:

uic file.ui -o file.py -g python
0
AfrosamuraiSPB On

To begin with, in Ubuntu I came across that the Error is written in the console: bash: qic. It is solved by installing pyside2-tools doing sudo apt-get install pyside2-tools. File conversion is performed by uic /usr/home/menu.ui > /usr/home/menu.py