Nominate our 2022 Qt Champions!

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 convert joystick values i used "toString "member function.

    the code is


    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":

    Sending over the network is a bit unclear. But another idea is to look at "QDataStream": on top of a well-chosen IODevice (like "QUdpSocket": )

    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": yourself.

Log in to reply