Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to convert joystick values to string
Forum Updated to NodeBB v4.3 + New Features

How to convert joystick values to string

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 2.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Arpitgarg
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • F Offline
      F Offline
      florent.revelut
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • G Offline
        G Offline
        goetz
        wrote on last edited by
        #3

        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.

        http://www.catb.org/~esr/faqs/smart-questions.html

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved