Results 1 to 4 of 4

Thread: QT crashed during running

  1. #1
    Join Date
    Jun 2018
    Posts
    2
    Qt products
    Qt5
    Platforms
    MacOS X

    Default QT crashed during running

    hi all,
    I've trying to load some data from file into a nested list. However, the application crashed during loading the data. I've put in some debug line in the code, and found the code crashed in appending data in my inner most list(line #76). Can someone please help me to understand what happened and how to fix it? Thanks.

    main.cpp
    Qt Code:
    1. #include "snp_plotter.h"
    2. #include "ui_snp_plotter.h"
    3. #include "QFile"
    4. #include "QFileDialog"
    5. #include "QTextStream"
    6. #include "QMessageBox"
    7. #include "QDebug"
    8. #include "QRegularExpression"
    9. #include "QRegularExpressionMatch"
    10. #include <QQueue>
    11. #include <QVector>
    12. #include <QList>
    13.  
    14. SNP_Plotter::SNP_Plotter(QWidget *parent) :
    15. QMainWindow(parent),
    16. ui(new Ui::SNP_Plotter)
    17. {
    18. ui->setupUi(this);
    19. this->setCentralWidget(ui->verticalLayoutWidget);
    20. }
    21.  
    22. SNP_Plotter::~SNP_Plotter()
    23. {
    24. delete ui;
    25. }
    26.  
    27. void SNP_Plotter::on_openSnpFile_clicked()
    28. {
    29. // clean up the currntfile cache
    30. QString openFile = QFileDialog::getOpenFileName(this,
    31. tr("Open SNP file"),
    32. "/usr",
    33. "SNP(*.s*p)"
    34. );
    35.  
    36. //extract number of ports
    37. QRegularExpression snpFormat(".s(\\d+)p");
    38. QRegularExpressionMatch match0 = snpFormat.match(openFile);
    39. nPorts = match0.captured(1);
    40. qint8 numberItems = 2*(nPorts.toInt()*nPorts.toInt())+1;
    41. listVector = new QList<QList<double>*>;
    42.  
    43. for(auto i=0; i<numberItems; i++){
    44. QList<double> *list = new QList<double>;
    45. (*listVector)[i] = list;
    46. }
    47.  
    48. //open file
    49. QFile file(openFile);
    50. if (!file.open(QIODevice::ReadOnly | QFile::Text)) {
    51. QMessageBox::warning(this, "Warning", "Cannot open file: " + file.errorString());
    52. return;
    53. }
    54.  
    55.  
    56. QTextStream dataReading(&file);
    57.  
    58. qint8 counter = 0;
    59. QRegularExpression headerFormat("#\\s+(\\w+)\\s+(\\w+)\\s+(\\w+)\\s+(\\w+)\\s+(\\w+)");
    60. QRegularExpression dataFormat("([^ ][-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?)");
    61. QString currentLine;
    62. while(!dataReading.atEnd()){
    63. //start a new line in the file
    64. currentLine = dataReading.readLine();
    65.  
    66. //type of lines to skip
    67. if((currentLine[0]=="\x0")||(currentLine[0]=="!") ){continue;}
    68.  
    69. //data extraction and insertion
    70. else if((currentLine[0]!="#")&&(currentLine[0]!="!")){
    71. QRegularExpressionMatchIterator dataList = dataFormat.globalMatch(currentLine);
    72. while(dataList.hasNext()){
    73. QRegularExpressionMatch matchedData = dataList.next();
    74. QString data = matchedData.captured(1);
    75. QList<double> *currentList= (*listVector)[counter%numberItems];
    76. currentList->append(data.toDouble());
    77. counter += 1;
    78. }
    79. }
    80.  
    81. //header type extraction
    82. else if ((currentLine[0]=="#")) {
    83. QRegularExpressionMatch match2 = headerFormat.match(currentLine);
    84. domainType = match2.captured(1);
    85. measureType = match2.captured(2);
    86. measureMethod = match2.captured(3);
    87. referenceImp = match2.captured(5);
    88. }
    89. }
    90. qInfo()<<(*listVector)[0]->size();
    91. // extraction completed, close file
    92. file.close();
    93. }
    To copy to clipboard, switch view to plain text mode 


    data:
    Qt Code:
    1. ! S3P File: Measurements: Mag<S11> Ang<S11> Mag<S12> Ang<S12> Mag<S13> Ang<S13>! row 1
    2. ! Mag<S21> Ang<S21> Mag<S22> Ang<S22> Mag<S23> Ang<S23>! row 2
    3. ! Mag<S31> Ang<S31> Mag<S32> Ang<S32> Mag<S33> Ang<S33>! row 3
    4.  
    5.  
    6.  
    7. # Hz S dB R 50
    8. 10000000 -52.282864 83.754532 -15.67896 -0.49186572 -1.5670134 -1.301762
    9. -15.748223 -0.10280456 -50.764286 149.86646 -56.900387 -70.843872
    10. -1.5776229 -1.2955924 -71.374367 -141.70441 -48.866203 65.932648
    11. 29987500 -60.731289 51.972256 -15.724875 -1.8122723 -1.5746148 -3.2653806
    12. -15.716247 -1.8535374 -52.617325 178.46486 -62.476551 5.2978568
    13. -1.5735339 -3.2886419 -65.686714 36.462376 -61.792774 9.9133005
    14. 49975000 -64.386765 2.9596229 -15.755823 -3.1201222 -1.5706615 -5.4831181
    15. -15.738674 -3.0600834 -52.237274 169.75545 -58.964714 27.526367
    16. -1.5741955 -5.4729681 -58.479481 47.793446 -56.108696 63.561378
    17. 69962500 -60.896507 -36.51757 -15.757278 -4.3601637 -1.577867 -7.6754441
    18. -15.747104 -4.3896055 -50.548729 177.66254 -57.043007 9.1148758
    19. -1.5749472 -7.6169047 -56.500164 6.8388286 -57.866039 -28.409134
    20. 89950000 -55.328976 -45.191593 -15.76739 -5.6117945 -1.5797645 -9.8418713
    21. -15.749889 -5.5769963 -50.809414 173.62177 -57.651119 -0.7305429
    22. -1.5803487 -9.7842817 -56.621773 5.4209571 -66.583694 23.118269
    23. 109937500 -60.013988 -42.251778 -15.770485 -6.7288284 -1.5785085 -12.021818
    24. -15.764176 -6.7430348 -51.211327 170.20062 -56.137653 -1.5785257
    25. -1.5805914 -11.985991 -55.860668 0.92532599 -58.335781 15.83968
    26. 129925000 -55.2337 -47.264515 -15.773083 -7.9232988 -1.5834771 -14.20496
    27. -15.74941 -7.9423704 -52.448433 166.58505 -57.46785 -5.3259425
    28. -1.5812542 -14.161623 -57.962692 0.68304181 -66.230148 -5.397459
    29. 149912500 -52.218529 -63.591721 -15.763268 -9.1296005 -1.5826913 -16.37332
    30. -15.770909 -9.0827551 -51.982231 165.33054 -56.151371 -14.161432
    31. -1.586452 -16.33128 -56.938805 -20.056446 -57.895336 -49.978813
    32. 169900000 -48.723946 -68.877541 -15.772202 -10.29782 -1.58857 -18.537006
    33. -15.756567 -10.253307 -53.100327 166.75829 -57.286308 -21.661839
    34. -1.5859301 -18.455862 -58.19286 -23.011927 -56.403473 -61.177219
    35. 189887500 -47.055653 -63.976929 -15.761551 -11.486256 -1.5892707 -20.66897
    36. -15.756705 -11.417432 -52.570255 161.31961 -58.11451 -14.260036
    37. -1.589681 -20.645853 -58.313042 -19.368044 -56.06601 -59.461319
    38. 209875000 -48.199955 -65.147034 -15.758836 -12.678895 -1.5931528 -22.858885
    39. -15.750708 -12.633892 -54.576355 159.43607 -57.476353 -23.090178
    40. -1.5905892 -22.808754 -57.229259 -22.673452 -53.756973 -77.388786
    41. 229862500 -47.620575 -65.079559 -15.761273 -13.856562 -1.5960027 -24.995838
    42. -15.757499 -13.857363 -54.944546 168.24443 -57.51046 -25.383596
    43. -1.5932056 -24.973335 -56.755974 -24.434172 -53.588017 -78.209816
    44. 249850000 -45.54829 -72.373695 -15.759305 -15.106434 -1.5959594 -27.192209
    45. -15.754061 -15.04305 -56.757584 167.29137 -57.757648 -35.331924
    46. -1.593374 -27.133352 -57.15892 -38.918037 -52.251003 -78.6092
    47. 269837500 -45.209282 -79.048836 -15.762296 -16.186449 -1.595193 -29.34836
    48. -15.761364 -16.268795 -56.31012 155.37877 -58.96965 -36.80077
    49. -1.6012613 -29.305353 -58.892376 -30.59782 -51.139919 -88.653198
    50. 289825000 -44.495762 -75.946327 -15.77701 -17.442837 -1.5954289 -31.487225
    51. -15.759547 -17.546104 -57.791164 136.05252 -58.239506 -44.324471
    52. -1.6040369 -31.49972 -58.461231 -38.748329 -50.686073 -102.10234
    53. 309812500 -43.302803 -82.000542 -15.766918 -18.634033 -1.5996813 -33.661705
    54. -15.761863 -18.641865 -61.730743 144.8166 -60.559978 -37.826778
    55. -1.6024027 -33.65374 -57.697384 -42.566422 -51.518753 -105.38393
    56. 329800000 -43.696449 -78.707024 -15.772308 -19.829834 -1.6114002 -35.827797
    57. -15.758872 -19.892492 -61.704247 131.07913 -60.35778 -39.423588
    58. -1.6023126 -35.767818 -59.314335 -32.67252 -52.212837 -96.09478
    59. 349787500 -41.770233 -79.74221 -15.764846 -21.037899 -1.6063002 -37.965122
    60. -15.761175 -21.141983 -67.287781 106.3756 -59.302685 -45.419971
    61. -1.6093071 -37.931061 -58.065773 -47.054985 -50.113159 -100.45293
    62. 369775000 -41.834766 -85.074005 -15.755595 -22.26008 -1.6062098 -40.106232
    63. -15.755444 -22.253096 -67.486336 95.830017 -60.84161 -46.56329
    64. -1.6086895 -40.089161 -59.786545 -45.948189 -49.895309 -123.41199
    65. 389762500 -40.628685 -85.450836 -15.762123 -23.489182 -1.6093255 -42.268429
    66. -15.763054 -23.396936 -68.248146 81.470787 -60.379967 -55.129562
    67. -1.608591 -42.201767 -61.377071 -50.809517 -50.866241 -127.41563
    68. 409750000 -40.523582 -86.431625 -15.7611 -24.674004 -1.6127316 -44.40868
    69. -15.759981 -24.647635 -75.545479 166.72386 -58.76609 -50.209095
    70. -1.6096529 -44.381767 -58.312939 -53.500042 -50.608158 -125.55299
    71. 429737500 -39.49865 -87.925888 -15.768126 -25.870119 -1.6137398 -46.560898
    72. -15.756283 -25.906502 -74.112823 -93.561935 -59.226101 -58.54623
    73. -1.6217877 -46.567924 -59.321663 -53.369888 -48.844105 -125.06399
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QT crashed during running

    What do you think happens when your code hits line 45? All you have done in line 41 is to allocate a -pointer-. You haven't given the QList that pointer points to any size. So if you have a zero-sized QList, and you try to assign something to the i-th member of it, what happens?
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Jun 2018
    Posts
    2
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: QT crashed during running

    Quote Originally Posted by d_stranz View Post
    What do you think happens when your code hits line 45? All you have done in line 41 is to allocate a -pointer-. You haven't given the QList that pointer points to any size. So if you have a zero-sized QList, and you try to assign something to the i-th member of it, what happens?
    Thanks for helping, I've tried to allocate the size of
    Qt Code:
    1. listVector
    To copy to clipboard, switch view to plain text mode 
    using the value from
    Qt Code:
    1. numberItems
    To copy to clipboard, switch view to plain text mode 
    at line 41, then initiate each nested list with pointers(line 44) that has many items(say 1000), however, the program still crashed.....

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QT crashed during running

    If you make listVector a QList (not QList *) member variable of your SNP_Plotter class, then you can use QList::push_back() to add new elements onto the the end of the list.

    Your logical error is in thinking that when you allocate a pointer, that also allocates a size for whatever list that is. It doesn't. All it does is allocate a pointer to a list. There is no list, just a pointer to a list. If you want to put things on the list, then you have to use list->push_back() or a similar method. And if what you have allocated is a pointer to a list of pointers to lists, then you have to make sure that what you are pushing onto the main list is pointers to lists that have been allocated with new() and not pointers to things you have created on the stack (e.g. list->push_back( &stackList); ). That will cause a crash too, because those stack things will be deleted as soon as the method that creates them exits and your stack will contain a bunch of pointers to deleted objects.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. qt crashed!
    By erfan in forum Qt Programming
    Replies: 3
    Last Post: 3rd July 2012, 18:27
  2. QFileDialog is crashed?
    By Gokulnathvc in forum Newbie
    Replies: 3
    Last Post: 19th December 2011, 08:16
  3. winId() crashed
    By nedivi in forum Qt Programming
    Replies: 1
    Last Post: 7th March 2011, 00:03
  4. QT Creator crashed on startup
    By eloos in forum Qt Tools
    Replies: 13
    Last Post: 20th November 2009, 09:50
  5. Crashed project
    By MarkoSan in forum Qt Programming
    Replies: 3
    Last Post: 26th January 2008, 01:25

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.