Results 1 to 10 of 10

Thread: vector causing system error/crash

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: vector causing system error/crash

    In the absence of your actual code this is what people assume you are doing:
    Qt Code:
    1. #include <iostream>
    2. #include <vector>
    3. using namespace std;
    4.  
    5. bool callVector(vector<float>& v)
    6. {
    7. v.push_back(1.2);
    8. v.push_back(2.3);
    9. return true;
    10. }
    11.  
    12. int main(int argc, char *argv[])
    13. {
    14. vector<float> vectorname;
    15. cout << vectorname.size() << endl;
    16.  
    17. // The following line is probably what you are doing
    18. // There is no element 0 and ranges are not checked
    19. // cout << "vector [0]\t" << vectorname[0]; //**system error/crash HERE **
    20.  
    21. bool res = callVector(vectorname);
    22. cout << res << "\t" << vectorname.size() << endl;
    23.  
    24. // This works now the vector has something in it
    25. cout << "vector [0]\t" << vectorname[0];
    26. }
    To copy to clipboard, switch view to plain text mode 

    Are you returning true from your callVector() routine when you should not perhaps?
    Last edited by ChrisW67; 13th October 2010 at 23:13.

  2. #2
    Join Date
    Apr 2010
    Location
    Singapore
    Posts
    156
    Thanks
    47
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: vector causing system error/crash

    The code :
    .h
    Qt Code:
    1. #include <vector>
    2. using namespace std;
    3.  
    4. bool callVector(vector<float>&);
    5. void func();
    6.  
    7. vector <float> vectorname;
    8. QString filename = "vector.txt";
    9. QFile file(filename);
    10. QString val;
    11. float v;
    To copy to clipboard, switch view to plain text mode 
    .cpp
    Qt Code:
    1. void myClass::func(){
    2. if(!callVector(vectorname))
    3. {
    4. qDebug() << " vector error" ;
    5. }
    6. else
    7. {
    8. qDebug()<<"vector success" ;
    9. }
    10. if (file.open(QIODevice::WriteOnly | QIODevice::Truncate))
    11. {
    12. for ( int i =0; i<vectorname.size() ; i++)
    13. {
    14. v = vectorname.at(i); //system crash here
    15. val = QString::number(v);
    16. qDebug()<< "val" << val;
    17. char *valtoAsciidata = val.toAscii().data();
    18. file.write(valtoAsciidata);
    19.  
    20.  
    21. }
    22. qDebug()<<"front =" << vectorname.front();
    23. qDebug()<<"back =" << vectorname.back();
    24. qDebug()<< "vector write finish!:" << "success";
    25. file.close();
    26.  
    27.  
    28. }
    29. else
    30. {
    31. qDebug()<<"error write vector.txt file";
    32. }
    33. }
    To copy to clipboard, switch view to plain text mode 

    The system crash with error as below when debugging:
    <Signal received>
    The inferior stopped because it received a signal from the Operating System
    Signal name : SIGSEGV
    Signal meaning : Segmentation fault
    The callVector is an API and it is called if dll is loaded. The code is in another program and the code is currently not transparent to me.

    The qDebug() returns "vector success" message when callVector is called in my program.
    Last edited by babygal; 14th October 2010 at 11:19.

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: vector causing system error/crash

    Are you absolutely sure that the callVector function is expecting a std::vector and not just space for a a plain old array of floats (i.e a float*)? Is vectorname.size() sensible when callVector returns? When the seg fault occurs what is the value of i?

    If you have the API prototype correct then you need to speak to the author or provider of the DLL.

Similar Threads

  1. Qt 4.7 SSE2 causing my app to crash
    By jonks in forum Qt Programming
    Replies: 8
    Last Post: 26th September 2010, 18:53
  2. QThread::wait() causing crash
    By Olliebrown in forum Qt Programming
    Replies: 3
    Last Post: 24th September 2010, 15:24
  3. Weird Windows Vista Permissions Causing Qmake Crash
    By CrazyIvanovich in forum Qt Programming
    Replies: 1
    Last Post: 4th June 2009, 21:52
  4. QTreeWidget->clear() causing crash after sort
    By Chuk in forum Qt Programming
    Replies: 7
    Last Post: 3rd September 2007, 09:59
  5. runtime error <vector>
    By mickey in forum General Programming
    Replies: 10
    Last Post: 5th September 2006, 12:18

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
  •  
Qt is a trademark of The Qt Company.