<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Qt IOs Magnetic field]]></title><description><![CDATA[<p dir="auto">Hello! Sorry for my bad English.<br />
Trying to get magnetic field data using the QMagnetometer class.<br />
Everything turns out if you set the returnGeoValues parameter to false (as by default). In this case, raw data is issued, but I need processed data. If I set the returnGeoValues parameter to true, then the values of the magnetic field x, y, z are set to 0. At the same time, reading-&gt; calibrationLevel () also gives 0, but it displays 1 for the first two or three conclusions.</p>
<p dir="auto">I am enclosing the code of my class for working with magnetic fields.<br />
Tell me, please, what am I doing wrong?<br />
Developed for IOs, version Qt 5.15.<br />
Thank!</p>
<pre><code>    #ifndef MAGNETO_H
    #define MAGNETO_H
     
    #include &lt;QObject&gt;
     
    #include &lt;QMagnetometer&gt;
    #include &lt;QMagnetometerFilter&gt;
    #include &lt;QMagnetometerReading&gt;
    #include "math.h"
     
    #include &lt;QDebug&gt;
     
    class Magneto : public QObject, public QMagnetometerFilter
    {
        Q_OBJECT
    public:
        explicit Magneto(QObject *parent = nullptr);
        ~Magneto();
     
        bool filter(QMagnetometerReading *reading);
     
        void start();
        void stop();
        bool isMagnetoStarted();
     
    private slots:
        void onSensorError(const int &amp;errorCode);
     
    signals:
        void dataReceived(const qreal &amp;x,
                          const qreal &amp;y,
                          const qreal &amp;z);
     
    private:
        QMagnetometer *m_magnetometer;
        qreal m_x;
        qreal m_y;
        qreal m_z;
        bool m_isStarted;
    };
     
    #endif // MAGNETO_H
</code></pre>
<pre><code>    #include "magneto.h"
     
    Magneto::Magneto(QObject *parent) : QObject(parent)
    {
        m_magnetometer = new QMagnetometer(this);
        m_magnetometer-&gt;addFilter(this);
        m_magnetometer-&gt;setReturnGeoValues(true);
     
        connect(m_magnetometer, SIGNAL(sensorError(int)),
                this, SLOT(onSensorError(int)));
     
        m_isStarted = false;
    }
     
    Magneto::~Magneto()
    {
        m_magnetometer-&gt;deleteLater();
    }
     
    bool Magneto::filter(QMagnetometerReading *reading)
    {
        qDebug() &lt;&lt; reading-&gt;calibrationLevel() &lt;&lt; reading-&gt;x() &lt;&lt; reading-&gt;y() &lt;&lt; reading-&gt;z();
     
        emit dataReceived(reading-&gt;x() * pow(10, 6),
                          reading-&gt;y() * pow(10, 6),
                          reading-&gt;z() * pow(10, 6));
    }
     
    void Magneto::onSensorError(const int &amp;errorCode)
    {
        qDebug() &lt;&lt; errorCode;
    }
     
    void Magneto::start()
    {
        m_isStarted = true;
        m_magnetometer-&gt;start();
    }
     
    void Magneto::stop()
    {
        m_isStarted = false;
        m_magnetometer-&gt;stop();
    }
     
    bool Magneto::isMagnetoStarted()
    {
        return m_isStarted;
    }
</code></pre>
]]></description><link>https://forum.qt.io/topic/116974/qt-ios-magnetic-field</link><generator>RSS for Node</generator><lastBuildDate>Wed, 07 Oct 2026 10:40:45 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/116974.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 13 Jul 2020 19:02:29 GMT</pubDate><ttl>60</ttl></channel></rss>