Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-118808

qt_add_translations with source autodetection mishandles id-based generated UI headers

    XMLWordPrintable

Details

    • Linux/Wayland, Windows
    • d52c7a886 (dev), 22f3c6ac5 (6.7), 51a08cc79 (6.6), 8a2d08562 (tqtc/lts-6.5), 666e7ad35 (dev), 4659b576a (6.7), 3f34ef350 (6.6), 0af897ccb (tqtc/lts-6.5), d39e9f21c (dev), 98d822d1b (6.7)

    Description

      Steps to reproduce:

      1. Create a simple C++ GUI application with a single UI file
      2. Ensure the UI file has the `idbasedtr="true"` attribute and is fully ID-based
      3. Ensure the C++ uses `qtTrId` consistently
      4. set `CMAKE_AUTOUIC_OPTIONS` to `-idbased` in `CMakeLists.txt`
      5. Call `qt_add_translations` on the application target
        1. Without specifying `SOURCES` manually
        2. With `LRELEASE_OPTIONS -idbased`
      6. Build the application
      7. Run `update_translations`

      This will produce a `.ts` file that contains translations with a context with an empty name, and which have the identifier as the source text, despite that the `ui_*.h` files use `qtTrId`, which should mark them as ID-based anyway. These duplicate the (correct) entries generated from the `.ui` files themselves.

      I tried to avoid this in a couple ways besides specifying SOURCES manually, but none of them worked:

      • Passing an extensions list that excluded .h files
      • Using clang via a compilation database, with a build dir outside the source dir, and passing `-project-roots` to exclude it

      This is because CMake generates a project JSON file that explicitly lists the generated headers, and that overrides both of these mechanisms as far as I can tell.

      This seems to be a confluence of no less than three suboptimal behaviors:

      1. `uic` fails to propagate the source text and comment fields to the header
      2. `lupdate` fails to properly treat `qtTrId` in such headers (lacking a `//%` comment) as being ID-based
      3. Despite `lupdate` supporting UI files directly, it's still passed the generated `ui_*.h` files as well

      (apologies for the mangled early submission, was fighting with the rich text editor)

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              jbornema Joerg Bornemann
              eternaleye Alex Elsayed
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: