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

QGuiApplication removes the main "-platform" parameter

    XMLWordPrintable

Details

    • Linux/X11, macOS, Windows

    Description

      #include "mainwindow.h"
      #include <QApplication>
      #include <QDebug>
      #include <QScreen>
      
      int main(int argc, char *argv[])
      {
      
          for (int i=0; i< argc; i++)
              qDebug() << "main parameter:" << QString::fromLatin1(argv[i]);
      
          int scaleFactor;
          {
              QGuiApplication a(argc, argv);
              scaleFactor=QGuiApplication::screens()[0]->logicalDotsPerInch() / 96.0f;
          }
      
          qputenv("Q_SCALE_FACTOR", QByteArray::number(scaleFactor));
      
          for (int i=0; i< argc; i++)
              qDebug() << "main parameter after QGuiApplication:" << QString::fromLatin1(argv[i]);
      
          QApplication a(argc, argv);
          return 0;
      }
      

      I run the program with the parameter -platform=minimal

      The result is:
      main parameter: "test123"
      main parameter: "-platform"
      main parameter: "minimal"
      main parameter after QGuiApplication: "test123"
      

      As you can see there is no logs:
      "main parameter after QGuiApplication: -platform"
      "main parameter after QGuiApplication: minimal"

      Why the parameters was removed?

      I noticed that QCoreApplicationn doesn't do this.

      The first QApplication call removes the "platform=minimal" parameter, so the second QApplication call tries to load the "xcb plugin" instead of "minimal plugin", which ends up with an error "qt.qpa.xcb: could not connect to display"

      Is there a way to check the name of the plugin that was loaded the first time QApplication was run ?

      Is there a better way to read the pixel density than creating a temporary QApplication object ?

      Attachments

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

        Activity

          People

            sorvig Morten Sørvig
            linusklan Krzysztof Guc
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes