Question on using QMC5883

I have a problem with the qmc5883 sensor. the output value of the sensor is not accurate does anyone have a solution? thank you

I attach the code and library that I use

#include <QMC5883L.h>
#include <Wire.h>

QMC5883L compass;

void setup()
{
	Wire.begin();

	compass.init();
	compass.setSamplingRate(50);

	Serial.begin(9600);
	Serial.println("QMC5883L Compass Demo");
	Serial.println("Turn compass in all directions to calibrate....");
}



void loop()
{
 	int heading = compass.readHeading();
	if(heading==0) {
		/* Still calibrating, so measure but don't print */
	} else {
		Serial.println(heading);
    delay(500);
  	}
}

The compass is not calibrated properly. Also, that code will work only if the magnetometer is held level, with the Z axis vertical.

Find another library, or just use the raw data from the one you have. First, follow the instructions in this tutorial to calibrate the magnetometer and correct the raw data: Tutorial: How to calibrate a compass (and accelerometer) with Arduino | Underwater Arduino Data Loggers

Thank you sir. But what should I do after I do that? Can I just use my sketch? or have to use a sketch of the calibration results? and do you have a library reference that I should use?

How about this sir? RepRage – How to measure your true heading with a HMC5883L magnetometer does it work for my QMC calibration?