Since you seem to be using Qml, you can take a look at 
https://doc.qt.io/qt-5/qml-qtquick-window-screen.html that could help you and 
have most of the job done, you could do your own qml singleton if you need to 
compute scale base on those value. You could access those property fom C++ and 
export you env vairbale if you really need to, but I would stick to View = Qml, 
keep thing in Qml as much as possible, so your view stay into the view layer.

Jérôme Godbout
Software / Firmware Lead

C: (581) 777-0050
O: (418) 800-1073 ext.: 109
godbo...@amotus.ca<mailto:godbo...@amotus.ca>
[cid:image001.png@01D70378.7E27B7D0]
dimonoff.com<https://www.dimonoff.com/>   |    
amotus.ca<https://www.amotus-solutions.com/>

From: Interest <interest-boun...@qt-project.org> On Behalf Of Anisha kaul
Sent: February 15, 2021 6:51 AM
To: interest@qt-project.org
Subject: [Interest] How to read screen information from QGuiApplication to put 
in qputenv environment variable?


Greetings,

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)

            QCoreApplication::exit(-1);

    }, Qt::QueuedConnection);

    engine.load(url);



    return app.exec();

}
_______________________________________________
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest

Reply via email to