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. QList Help
Qt 6.11 is out! See what's new in the release blog

QList Help

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 745 Views 2 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.
  • R Offline
    R Offline
    RCtaf
    wrote on last edited by
    #1

    Hi everyone,
    here's my issue, i'm trying to get QList data from a class to my main.
    My code is suppose to get a joystick event then i put it in a QList which i then return,see the code below.
    here is my code :

    
    QList <int> Rjoystick::datAxis(int i)
    {
        QList <int>axis;
    
        m_joystick = SDL_JoystickOpen(i);
        SDL_JoystickEventState(SDL_ENABLE);
        SDL_Event event;
    
        SDL_PollEvent(&event);
    
        switch (event.type) {
        case SDL_JOYAXISMOTION:
        axis.insert(event.jaxis.axis,event.jaxis.value);
          break;
    
        default:
            break;
        }
    
        SDL_JoystickClose(m_joystick);
        return axis;
    }
    

    and here's the code fto get some data from the QList on the main.

    QList <int> g;
    
       g = r.datAxis(0);
       qDebug() <<g.at(0);
    

    i'm getting this error : "ASSERT failure in QList<T>::at: "index out of range"

    thamk you foryour help.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      There's no garanti that datAxis returns a non empty list. You should check that before using that function return value.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • R Offline
        R Offline
        RCtaf
        wrote on last edited by
        #3

        So i modify the code and it's seems that you are right, i think my problem maybe coming from the function "insert". At this point i don't know how will i get the Joystick data into my QList, if you got any advice, i will take it.

        mrjjM 1 Reply Last reply
        0
        • R RCtaf

          So i modify the code and it's seems that you are right, i think my problem maybe coming from the function "insert". At this point i don't know how will i get the Joystick data into my QList, if you got any advice, i will take it.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @RCtaf
          I was wondering something else
          what is
          event.jaxis.axis,event.jaxis.value
          ?
          What values do they have?
          As if event.jaxis.axis is not zero, you ask it to insert event.jaxis.value at some
          index which list might not have (yet) -> giving "index out of range"
          You could do
          axis.append(event.jaxis.value); to simply store the values but
          you might need event.jaxis.axis for something also ?

          1 Reply Last reply
          1
          • R Offline
            R Offline
            RCtaf
            wrote on last edited by RCtaf
            #5

            Well, event.jaxis.axis hold a integer it's the axis being moved, can be 0 or 4 depends of what axis of the joystick is being moved.
            And event.jaxis.value hold the value of the which the joystick is moved can be anything between roughly -32000 to 32000.

            mrjjM 1 Reply Last reply
            0
            • R RCtaf

              Well, event.jaxis.axis hold a integer it's the axis being moved, can be 0 or 4 depends of what axis of the joystick is being moved.
              And event.jaxis.value hold the value of the which the joystick is moved can be anything between roughly -32000 to 32000.

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @RCtaf
              Hi
              In that case, you could do
              QList<int> axis{0,0,0,0,0};
              then
              axis.insert(event.jaxis.axis,event.jaxis.value);
              will work as expected.
              (as list has 5 ints)
              I assume then event.jaxis.axis can have value 0-4 ?
              When you read it back you can check which index has non zero to see
              which axes was changed.

              1 Reply Last reply
              2
              • R Offline
                R Offline
                RCtaf
                wrote on last edited by
                #7

                Did that, And it is working just perfectly.

                Thank you for help.

                1 Reply Last reply
                1

                • Login

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