I want to call the reboot function in the vehicle class from the main.cc file. Tried for 2 complete days but not working at all. When trying to access from the qml code from where it is already called iam getting an error telling Typeerror: cannot call the method ‘reboot’ of null type. Can someone please help how can this method be called from the main function. Please please do help
That means your vehicle object is null.
Iam trying to call the reboot option with the vehicle object but then there is no default constructor available. How do we load the parameters for the vehicle object. From where can we load the parameters for the constructor? Iam actually stuck with this issue even today. Can you please help me in getting the correct parameters for the constructor.
You never construct a Vehicle from the qml side. You ask for the active vehicle using this
qDebug() << “Trying to use the reboot function”;
Vehicle* vehicle = nullptr; vehicle = qgcApp()->toolbox()->multiVehicleManager()->activeVehicle(); vehicle->rebootVehicle();
I tried it this from main function it dint work
I tried to get the active vehicle from the qml side too but dint know how to call the vehicle constructor from the qml side
Then at the point in time you called it there was no activeVehicle known to QGC.
No sir the vehicle was connected using a simulator but the application is crashing with an error. Dint know wat was the exact issue. My only requirement is to reboot the vehicle when we close the application. Is there a way to implement this sir? Iam entirely new to this codebase. Will be so glad if you help me
When you close the app all the existing connections are closed and the vehicles will go away. Hence the place you put you reboot code is wrong since the vehicle is already gone. You will need to find the place in the code which handles app close and ask the vehicle to reboot before it closes the connection to the vehicle.
So sir can we have this piece of code
Vehicle* vehicle = nullptr;
vehicle = qgcApp()->toolbox()->multiVehicleManager()->activeVehicle();
somewhere in the start of the main function to have this feature? Or can we have a seperate button type using qml to implement this requirement/ Which will be the better way sir?
How will the code flow be sir then? So can we just keep a button and use QGroundControl.multiVehicleManager.activeVehicle.rebootvehicle to reboot it?
No you cannot.
You need to do this.
Thank you so much. I tried to call from qml. It resolved the issue.