Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. Compilation of Qt5.3.1 on Ubuntu 20.04.1 - QCommandLineParser addVersionOption() Issue

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

Scheduled Pinned Locked Moved Unsolved Installation and Deployment
5 Posts 3 Posters 710 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    laurent.c
    wrote on last edited by
    #1

    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.

    aha_1980A 1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

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

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      L 1 Reply Last reply
      1
      • L laurent.c

        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.

        aha_1980A Offline
        aha_1980A Offline
        aha_1980
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @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

        Qt has to stay free or it will die.

        L 1 Reply Last reply
        0
        • Christian EhrlicherC Christian Ehrlicher

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

          L Offline
          L Offline
          laurent.c
          wrote on last edited by
          #4

          @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.

          1 Reply Last reply
          0
          • aha_1980A aha_1980

            @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

            L Offline
            L Offline
            laurent.c
            wrote on last edited by laurent.c
            #5

            @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.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved