Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Compilation of Qt5.3.1 on Ubuntu 20.04.1 - QCommandLineParser addVersionOption() Issue



  • Hello,

    I'm trying to compile Qt5.3.1 on Ubuntu 20.04.1 (see this thread for other issues I encountered with foreach loops : https://forum.qt.io/topic/121528/compilation-of-qt5-3-1-on-ubuntu-20-04-1)

    I could compile OK, but then I discovered another issue at runtime, e.g. 'moc--version' gives "Unknown option 'version'" (the same happens with 'rcc' and 'uic').

    I actually saw many of those messages during compilation:

    QCommandLineParser: option not defined: "version"
    QCommandLineParser: option not defined: "help"
    

    Although I felt it was probably not normal, I did not look into it as it did not stop me compiling.

    But now, I've been investigating this warnings due to the runtime issue, and here is what I found:

    In main.cpp of moc for example, there are calls to parser.addVersionOption() and parser.addHelpOption() so I looked into those methods in src/corelib/tools/qcommandlineparser.cpp.

    QCommandLineOption QCommandLineParser::addVersionOption()
    {
        QCommandLineOption opt(QStringList() << QStringLiteral("v") << QStringLiteral("version"), tr("Displays version information."));
        addOption(opt);
        d->builtinVersionOption = true;
        return opt;
    }
    

    We see that addVersionOption() calls addOption(). So I added some debug and here what I found:

    QCommandLineParser: addOptionVersion size = 2       => Correct  size of QStringList (arg 1 of QCommandLineOption)
    QCommandLineParser: addOption optionNames size = 1  => Wrong size of QStringList (option.names.size()) !
    QCommandLineParser: addOption iterating name = v    => So in the loop (replaced by a for loop instead of foreach!), only 'v' gets parsed, not 'version'
    

    To try, I changed the code to:

    QCommandLineOption opt(QStringList() << QStringLiteral("version"), tr("Displays version information."));
    

    Then it works fine, and 'moc --version' returns the expected value (+ QCommandLineParser: option not defined: "version" warning disappears of course).

    I'm not able to explain why the QStringList is not passed correctly. So that's where I'm requesting your help trying to understand what's going on !

    I'm compiling using GCC 9.3.0.

    Thanks in advance.


  • Lifetime Qt Champion

    I would take a look in the git history of QCommandLineOption to see if there were fixes/changes to make it work with gcc9


  • Lifetime Qt Champion

    @laurent-c if you really want to keep such an old Qt version (why?), wouldn't it be easier to set up a docker environment for that?

    Regards



  • @Christian-Ehrlicher That's what I've done, and this line is identical in the latest code. Looking at the git log, I could not find anything relevant.



  • @aha_1980 I'm actually cross-compiling Qt for my embedded device. And I cannot upgrade to latest Qt. I'm cross-compiling for arm (using gcc 4.8 from Linaro toolchain). However, the tools themselves are compiled using the host machine GCC as they have to run on the host machine.


Log in to reply