PDA

View Full Version : Transferring data to QMap



saad_saadi
29th August 2013, 05:29
Hello Everyone,

I am doing one project in which I define a data types like below


typedef QVector<double> QFilterDataMap1D;

typedef QMap<double, QFilterDataMap1D> QFilterDataMap2D;



Then there is one class with the name of mono_data in which i have define this variable

QFilterMap2D valid_filters;


mono_data Scan_data // Class
Now i am reading one variable from a .mat file and trying to save it in to above "valid_filters" QMap.



for(int i=0;i<1;i++)
{
for(int j=0;j<1;j++)
{
Scan_Data.valid_filters[i][j]=valid_filters[i][j];
printf("\nValid_filters=%f",Scan_Data.valid_filters[i][j]);
}
}

The transferring is done successfully but then it gives run-time error


Windows has triggered a breakpoint in SpectralDataCollector.exe.

This may be due to a corruption of the heap, and indicates a bug in SpectralDataCollector.exe or any of the DLLs it has loaded.

The output window may have more diagnostic information

Can anyone help in solving this problem. It will be of great help to me.

Thanks

Santosh Reddy
29th August 2013, 05:56
Scan_Data.valid_filters[i][j]
The array operator will crash the software if the valid_filter map does not have the i th item, and will also crash if j th item is not present in the vector.

Make sure before writing the vector value that index is present in the vector, and also make sure that index item (vector) is present in the map.

saad_saadi
29th August 2013, 06:07
Dear Sir,

Thanks a lot for the reply. But unfortunately i didn't understand your answer completely..(sorry for my less understanding of qt concept)..can you please define the data type for me or do you think that i can use here 2D QVector?

Thanks again

Santosh Reddy
29th August 2013, 06:19
Does this make sense


for(int i=0;i<1;i++)
{
QFilterDataMap1D temp;
for(int j=0;j<1;j++)
{
temp.append(valid_filters[i][j]);
}
Scan_Data.valid_filters.insert(i, temp);
}

for(int i=0;i<1;i++)
{
for(int j=0;j<1;j++)
printf("\nValid_filters=%f",Scan_Data.valid_filters[i][j]);
}

saad_saadi
29th August 2013, 07:31
Dear Sir,

Thanks a lot for the reply. Can you please check this your code, I modified for 3D?



for(int i=0;i<1025;i++)
{
QFilterDataMap1D temp;
for(int j=0;j<153;j++)
{
for(int k=0;k<3;k++)
temp.append(valid_filters[i][j][k]);
}
Scan_Data.valid_filters.insert(i, temp);
}

for(int i=0;i<1025;i++)
{
for(int j=0;j<153;j++)
for(int k=0;k<3;k++)
printf("\nValid_filters=%f",Scan_Data.valid_filters[i][j][k]);
}

Santosh Reddy
29th August 2013, 07:37
What do you want to do?

saad_saadi
29th August 2013, 07:40
Similarly want to save a 3D variable from a .mat file.


typedef QVector<double> QFilterDataMap1D;
typedef QMap<double, QFilterDataMap1D> QFilterDataMap2D;
typedef QMap<double, QFilterDataMap2D> QFilterDataMap3D;


QFilterDataMap3D data_3D

I want to save a 3D variable from .mat file into data_3D QMap.

Santosh Reddy
29th August 2013, 08:06
This how it should be done


typedef QVector<double> QFilterDataMap1D;
typedef QMap<double, QFilterDataMap1D> QFilterDataMap2D;
typedef QMap<double, QFilterDataMap2D> QFilterDataMap3D;

QFilterDataMap3D data_3D

for(int i=0;i<1025;i++)
{
QFilterDataMap2D temp2D;
for(int j=0;j<153;j++)
{
QFilterDataMap1D temp;
for(int k=0;k<3;k++)
{
temp2.append(valid_filters[i][j][k]);
}
temp2D.insert(j, temp2);
}
data_3D.insert(i, temp2D);
}

for(int i=0;i<1025;i++)
{
for(int j=0;j<153;j++)
for(int k=0;k<3;k++)
printf("\nValid_filters=%f",data_3D[i][j][k]);
}

saad_saadi
4th September 2013, 06:48
Dear Sir,

Sorry for disturbing you again. Now i want to do the reverse, means what to transfer QFilterMap2D data to a 2D matrix. first let assume an example for QMapFilter1D, it will be like this


typedef QVector<double> QFilterDataMap1D
typedef QMap<double, QFilterDataMap1D> QFilterDataMap2d
QFilterDataMap1d map1d;
QFilterDataMap2D map2d;
double gain;
double gain2[1][153];

I want to transfer map2d into gain2. Can you please tell me how i can do this.

Thanks in advance.

Santosh Reddy
4th September 2013, 06:59
I want to QFilterDataMap1D into gain and QFilterDataMap2D into gain2.
You cannot, QFilterDataMap1D is type and gain is a variable. You will need a variable of QFilterDataMap1D/QFilterDataMap2D first


typedef QVector<double> QFilterDataMap1D
typedef QMap<double, QFilterDataMap1D> QFilterDataMap2d


QFilterDataMap1D mapID;
QFilterDataMap2d map2d;
...

double gain;
double gain2[1][153];

//lets assume mapID has 153 doudle values in it and you want to read 10'th double item (index = 9)
gain = mapID.at(9);

//lets assume map2d has 10 QFilterDataMap1D in it and each QFilterDataMap1D has 153 double values, and you want read all the double values of 5th item (key = 4)
for(int i = 0; i < map2d.value(4).size(); i++)
{
gain2[0][i] = map2d[4][i];
}

saad_saadi
4th September 2013, 07:10
Thanks a lot for pointing the mistake, i meant the same for which you answered..i edited my question..
In my case map2d has 3 QFilterDataMap1D in it and which in turn each has 153 double values, so my index will be like this



for(int j=0;j<3;j++)
for(int i=0, i<map2d.value(j).size();i++)
{
gain2[j][i]=map2d[j][i];
}

How about this case

typedef QVector<double> QFilterDataMap1D;
typedef QMap<double, QFilterDataMap1D> QFilterDataMap2D;
typedef QMap<double, QFilterDataMap2D> QFilterDataMap3D;

QFilterDataMap3D map3d;
double gain3[1024][153][3];

How i can transfer QFilterDataMap3D into gain3?

Thanks a lot for you concern in advance.