Results 1 to 11 of 11

Thread: Transferring data to QMap

  1. #1
    Join Date
    Jul 2013
    Posts
    16
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Transferring data to QMap

    Hello Everyone,

    I am doing one project in which I define a data types like below
    Qt Code:
    1. typedef QVector<double> QFilterDataMap1D;
    2.  
    3. typedef QMap<double, QFilterDataMap1D> QFilterDataMap2D;
    To copy to clipboard, switch view to plain text mode 

    Then there is one class with the name of mono_data in which i have define this variable
    Qt Code:
    1. QFilterMap2D valid_filters;
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. mono_data Scan_data // Class
    To copy to clipboard, switch view to plain text mode 
    Now i am reading one variable from a .mat file and trying to save it in to above "valid_filters" QMap.

    Qt Code:
    1. for(int i=0;i<1;i++)
    2. {
    3. for(int j=0;j<1;j++)
    4. {
    5. Scan_Data.valid_filters[i][j]=valid_filters[i][j];
    6. printf("\nValid_filters=%f",Scan_Data.valid_filters[i][j]);
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 
    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
    Last edited by saad_saadi; 29th August 2013 at 06:59.

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: QMap Memory error

    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.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Jul 2013
    Posts
    16
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QMap Memory error

    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

  4. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: QMap Memory error

    Does this make sense
    Qt Code:
    1. for(int i=0;i<1;i++)
    2. {
    3. QFilterDataMap1D temp;
    4. for(int j=0;j<1;j++)
    5. {
    6. temp.append(valid_filters[i][j]);
    7. }
    8. Scan_Data.valid_filters.insert(i, temp);
    9. }
    10.  
    11. for(int i=0;i<1;i++)
    12. {
    13. for(int j=0;j<1;j++)
    14. printf("\nValid_filters=%f",Scan_Data.valid_filters[i][j]);
    15. }
    To copy to clipboard, switch view to plain text mode 
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  5. The following user says thank you to Santosh Reddy for this useful post:

    saad_saadi (29th August 2013)

  6. #5
    Join Date
    Jul 2013
    Posts
    16
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QMap Memory error

    Dear Sir,

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

    Qt Code:
    1. for(int i=0;i<1025;i++)
    2. {
    3. QFilterDataMap1D temp;
    4. for(int j=0;j<153;j++)
    5. {
    6. for(int k=0;k<3;k++)
    7. temp.append(valid_filters[i][j][k]);
    8. }
    9. Scan_Data.valid_filters.insert(i, temp);
    10. }
    11.  
    12. for(int i=0;i<1025;i++)
    13. {
    14. for(int j=0;j<153;j++)
    15. for(int k=0;k<3;k++)
    16. printf("\nValid_filters=%f",Scan_Data.valid_filters[i][j][k]);
    17. }
    To copy to clipboard, switch view to plain text mode 

  7. #6
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: QMap Memory error

    What do you want to do?
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  8. #7
    Join Date
    Jul 2013
    Posts
    16
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QMap Memory error

    Similarly want to save a 3D variable from a .mat file.

    Qt Code:
    1. typedef QVector<double> QFilterDataMap1D;
    2. typedef QMap<double, QFilterDataMap1D> QFilterDataMap2D;
    3. typedef QMap<double, QFilterDataMap2D> QFilterDataMap3D;
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. QFilterDataMap3D data_3D
    To copy to clipboard, switch view to plain text mode 

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

  9. #8
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: QMap Memory error

    This how it should be done
    Qt Code:
    1. typedef QVector<double> QFilterDataMap1D;
    2. typedef QMap<double, QFilterDataMap1D> QFilterDataMap2D;
    3. typedef QMap<double, QFilterDataMap2D> QFilterDataMap3D;
    4.  
    5. QFilterDataMap3D data_3D
    6.  
    7. for(int i=0;i<1025;i++)
    8. {
    9. QFilterDataMap2D temp2D;
    10. for(int j=0;j<153;j++)
    11. {
    12. QFilterDataMap1D temp;
    13. for(int k=0;k<3;k++)
    14. {
    15. temp2.append(valid_filters[i][j][k]);
    16. }
    17. temp2D.insert(j, temp2);
    18. }
    19. data_3D.insert(i, temp2D);
    20. }
    21.  
    22. for(int i=0;i<1025;i++)
    23. {
    24. for(int j=0;j<153;j++)
    25. for(int k=0;k<3;k++)
    26. printf("\nValid_filters=%f",data_3D[i][j][k]);
    27. }
    To copy to clipboard, switch view to plain text mode 
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  10. The following user says thank you to Santosh Reddy for this useful post:

    saad_saadi (29th August 2013)

  11. #9
    Join Date
    Jul 2013
    Posts
    16
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Transferring data to QMap

    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

    Qt Code:
    1. typedef QVector<double> QFilterDataMap1D
    2. typedef QMap<double, QFilterDataMap1D> QFilterDataMap2d
    3. QFilterDataMap1d map1d;
    4. QFilterDataMap2D map2d;
    5. double gain;
    6. double gain2[1][153];
    To copy to clipboard, switch view to plain text mode 

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

    Thanks in advance.
    Last edited by saad_saadi; 4th September 2013 at 07:03.

  12. #10
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Transferring data to QMap

    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
    Qt Code:
    1. typedef QVector<double> QFilterDataMap1D
    2. typedef QMap<double, QFilterDataMap1D> QFilterDataMap2d
    3.  
    4.  
    5. QFilterDataMap1D mapID;
    6. QFilterDataMap2d map2d;
    7. ...
    8.  
    9. double gain;
    10. double gain2[1][153];
    11.  
    12. //lets assume mapID has 153 doudle values in it and you want to read 10'th double item (index = 9)
    13. gain = mapID.at(9);
    14.  
    15. //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)
    16. for(int i = 0; i < map2d.value(4).size(); i++)
    17. {
    18. gain2[0][i] = map2d[4][i];
    19. }
    To copy to clipboard, switch view to plain text mode 
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  13. #11
    Join Date
    Jul 2013
    Posts
    16
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Transferring data to QMap

    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

    Qt Code:
    1. for(int j=0;j<3;j++)
    2. for(int i=0, i<map2d.value(j).size();i++)
    3. {
    4. gain2[j][i]=map2d[j][i];
    5. }
    To copy to clipboard, switch view to plain text mode 

    How about this case
    Qt Code:
    1. typedef QVector<double> QFilterDataMap1D;
    2. typedef QMap<double, QFilterDataMap1D> QFilterDataMap2D;
    3. typedef QMap<double, QFilterDataMap2D> QFilterDataMap3D;
    4.  
    5. QFilterDataMap3D map3d;
    6. double gain3[1024][153][3];
    To copy to clipboard, switch view to plain text mode 

    How i can transfer QFilterDataMap3D into gain3?

    Thanks a lot for you concern in advance.
    Last edited by saad_saadi; 4th September 2013 at 07:31.

Similar Threads

  1. Replies: 2
    Last Post: 8th July 2013, 12:14
  2. Memory Error
    By spongebob in forum Qt Programming
    Replies: 2
    Last Post: 7th May 2010, 13:27
  3. How to Calculate the memory occupied by a QMap object
    By ahmedb in forum Qt Programming
    Replies: 5
    Last Post: 6th May 2010, 13:26
  4. QMap error
    By afflictedd2 in forum Qt Programming
    Replies: 4
    Last Post: 8th April 2009, 19:30
  5. Error with QMap
    By xgoan in forum Qt Programming
    Replies: 1
    Last Post: 17th November 2008, 11:07

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.