[Interest] How to read screen information from QGuiApplication to put in qputenv environment variable?

Anisha kaul anisha.kaul.1983 at gmail.com
Mon Feb 15 12:50:39 CET 2021


The problem is that qputenv does not work if written after the
initialization of QGuiApplication.

I want to calculate scale according to the information from QGuiApplication.

How do I do it? The following code throws a segmentation fault.



#include <QGuiApplication>#include <QQmlApplicationEngine>#include
<QScreen>#include <QDebug>int main(int argc, char *argv[]){
    qreal abc = QGuiApplication::primaryScreen()->physicalDotsPerInch();

    qDebug() << "null " << abc;

    qputenv("QT_SCALE_FACTOR", "2");

    QGuiApplication app(argc, argv);

    QQmlApplicationEngine engine;
    const QUrl url(QStringLiteral("qrc:/main.qml"));
    QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                     &app, [url](QObject *obj, const QUrl &objUrl) {
        if (!obj && url == objUrl)
    }, Qt::QueuedConnection);

    return app.exec();
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20210215/5cbe9bef/attachment.html>

More information about the Interest mailing list