Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to add integers into array
Forum Updated to NodeBB v4.3 + New Features

How to add integers into array

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 2.5k 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.
  • G Offline
    G Offline
    ganaa
    wrote on 18 May 2014, 09:00 last edited by
    #1

    Hello
    i am new at QT so some errors i have

    i need to record three audio channel data streaming in.

    So i have created three arrays and checked how is it working but it seems array is not working normally,

    Three array has same values even if i give different channels. Channels show me exactly different numbers in text view as single numbers and i need to record them into three different arrays but same values but order is different

    @
    static int neg[]={};
    static int xoer[]={};
    static int guraw[]={};
    static int nem=0;
    @

    here is loop
    @{
    neg[nem]=(chan1.toInt());//string to int
    xoer[nem]=(chan2.toInt());
    guraw[nem]=(chan3.toInt());

    nem=nem+1;           
    

    }
    @

    after loop finishes i print them to see the three channel values

    @
    {

    for(int kaka=0;kaka<=nemex1;kaka++){
         QString let= QString::number(neg[kaka]);
         stringList->append(let);
         listModel->setStringList(*stringList);
    }
    
    for(int kaka1=0;kaka1<=nemex2;kaka1++){
        QString let1= QString::number(xoer[kaka1]);                            
        stringList->append(let1);
        listModel->setStringList(*stringList);
     }
    
    
    for(int kaka2=0;kaka2<=nemex3;kaka2++){
        QString let2= QString::number(guraw[kaka2]);
        stringList->append(let2);
        listModel->setStringList(*stringList);
    }
    

    }
    @

    then results are :
    chan1 : 6 270 274 0 261 270 0
    chan2 : 270 274 0 261 270 0 265
    chan3 : 274 0 261 270 0 265 274

    just results are shifted but same no difference

    and other thing is threshold was 270 but there are numbers lower than 270...it means nothing is working normally

    what is wrong with me or QT?

    [edit Added missing coding tags @ SGaist]

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 18 May 2014, 20:34 last edited by
      #2

      Hi,

      Why static arrays ?

      Why are you using a pointer to a QStringList ? This class is implicitly shared

      Why are you assigning the string list each time in the for loop ? Once at the end is enough.

      Are you sure that using the same string list and same listModel for each channel is the right thing ?

      Also, why are you storing the values in an array of int if you are going the convert them back to string ?

      Do you only get one int value each time for each channel ?

      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
      0
      • G Offline
        G Offline
        ganaa
        wrote on 19 May 2014, 02:19 last edited by
        #3

        i am new so i found the example and that's why i am not well

        you are right listModel is same but assigned values are different in each loop
        so i thought list model is just a box. and i am putting let, let1, let2 simultaneously.

        converting to the string is just to see or check normal work.
        i will delete int to string after it works well.

        my code is big so i am checking them after i wrote.

        i am actually converting my project of MATLAB in to QT. so write one function and check result.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 19 May 2014, 21:32 last edited by
          #4

          Then you should first get yourself familiar with c++ and Qt before rushing the port. Start by a small simple function and don't forget to add tests to ensure your code is working properly.

          On a side note, it's Qt, QT stands for Apple QuickTime

          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
          0

          1/4

          18 May 2014, 09:00

          • Login

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