[SOLVED]How to store data present in the tableview in any 2D array ?



  • I have a tableview which is contains 32 rows and 32 column . Each cell is a comboboxdelegate (each cell is a combobox) which contains several items in the list. User has the ability to change the values of comboboxdelegate .I have a radiobutton "Tx" and "Rx" . on clicking "Tx"/"Rx" the tableview should display the values which was selected by the user for Tx/Rx in the same tableview. I have to store the data for each of Tx/Rx in a 2D array and update the data as the user updates. On Tx/Rx radiobutton click i want to retrieve the value from 2D array and display it in the tableview .
    How to store data present in the tableview in any 2D array ? and how to retrieve the value from 2D array and display it in the tableview?


  • Lifetime Qt Champion

    Hi,

    You can build your own model on top of e.g. two QVector<QVector<whatever_type_you_need>> that you will switch when changing Tx/Rx

    Hope it helps



  • @SGaist
    Hi.Thanks for the reply.
    How about storing values in Qstring ?

        QString TxDataTables[32][32];
        for(int row=0;row<32;row++)
        {
            for (int column=0;column<32;column++)
            {
             QModelIndex index = DataTableModel->index(row, column, QModelIndex());
             TxDataTables[row][column] = index.data().toString();
            }
        }
    

    how to retrieve the data when Tx/Rx changed ?


  • Lifetime Qt Champion

    Depends on whether you store both information in your strings or if you have two tables



  • @SGaist
    I want to store the data in the string .


  • Lifetime Qt Champion

    Then you have to parse the string each time. Wouldn't it be more practical to use a QPair ?



  • @SGaist
    I have done it with the structure

    RTStruct *rtStruct;
        for(int row=0;row<32;row++)
        {
            rtStruct = rtList.at(row);
            for (int column=0;column<32;column++)
            {
           QModelIndex index = DataTableModel->index(row, column, QModelIndex());
                if(addressArea == TX)
                {
                    rtStruct->txDataTables[column] = index.data().toString();
                }
                else
                {
                    rtStruct->rxDataTables[column] = index.data().toString();
                }
            }
        }
    

    How to do it with Qpair?


  • Lifetime Qt Champion

    If you already have a struct that fits your needs then no need to change anything



  • @SGaist
    Yes, It worked me out.


Log in to reply
 

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