How to convert joystick values to string
-
hi, am doing a project in which i have to read joystick values and send them to another comp . I am able to read joystick values, but not able to bundle them together . I tried doing this using by creating string.to convert joystick values i used "toString "member function.
the code is
@
lcd1->display(joystick->getAxis(0));
lcd2->display(joystick->getAxis(1));
lcd3->display(joystick->getAxis(2));
lcd4->display(joystick->getAxis(3));a1=(joystick->getAxis(0)).toString(); a2=(joystick->getAxis(1)).toString(); a3=(joystick->getAxis(2)).toString(); a4=(joystick->getAxis(3)).toString();@
I am able to read and display values correctly
but this converting to string gives an error::Request for member function "toString();" ,which is of non class type int
how can i remove this error.
also is there any other way to send all joystick value as a packet over a network -
looks like
- your joystick->getAxis() returns an int.
- int has no method toString (it's a base scalar type)
if a1 is a QString (I suppose it is ?), you can use "QString::number":http://doc.qt.nokia.com/4.7/qstring.html#number-4
Sending over the network is a bit unclear. But another idea is to look at "QDataStream":http://doc.qt.nokia.com/4.7/qdatastream.html on top of a well-chosen IODevice (like "QUdpSocket":http://doc.qt.nokia.com/4.7/qudpsocket.html )
Note that sending to another computer, you need to decide of a protocol... Sounds to me that datagram would fit your need.
-
There is no general toString() like in java. You'll have to convert to QString with that's static methods:
@
QString a1 = QString::number(joystick->getAxis(0));
@You could have found this from the fine "QString documentation":http://doc.qt.nokia.com/4.7/qstring.html yourself.