[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 13:48:47 CET 2021


Well, thank you for the response and for the idea about creation and
deletion of objects. I tried it and it worked.
I am feeling though that it is not a good way of writing code.
Am I trying to solve a wrong problem?

My aim is to run this application on screens of different PPI. So, I
thought that I can get the PPI and set the scale accordingly.
Any other suggestions about some proper way to solve this?

On Mon, Feb 15, 2021 at 5:54 PM Tor Arne Vestbø <Tor.arne.Vestbo at qt.io>
wrote:

> Can I ask, why do you want to set QT_SCALE_FACTOR at all?
>
> Cheers,
> Tor Arne
>
> On 15 Feb 2021, at 12:50, Anisha kaul <anisha.kaul.1983 at gmail.com> wrote:
>
> 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 at qt-project.org
> https://lists.qt-project.org/listinfo/interest
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20210215/a3793800/attachment.html>


More information about the Interest mailing list