How to add integers into array



  • 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]


  • Lifetime Qt Champion

    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 ?



  • 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.


  • Lifetime Qt Champion

    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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.