Results 1 to 11 of 11

Thread: runtime error <vector>

  1. #1
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default runtime error <vector>

    HI, I have a SLOT
    Qt Code:
    1. slot() {
    2. vector <QWidget*> tabs;
    3. vector<QSpinBox*> sbx;
    4. vector<QSpinBox*> sby;
    5. vector<QSpinBox*> sbz;
    6.  
    7. cout << "problem \n";
    8. tabs.push_back(tab0);
    9. tabs.push_back(tab1);
    10. tabs.push_back(tab2);
    11. tabs.push_back(tab3);
    12. tabs.push_back(tab4);
    13. tabs.push_back(tab5);
    14. tabs.push_back(tab6);
    15. tabs.push_back(tab7);
    16. cout << " END problem \n";
    17. }
    To copy to clipboard, switch view to plain text mode 
    this slot can be called many time; it happen that the 3th or 4th time, generate a bug error;
    "cout << " END problem \n";" isn't print..........do anyone know why??? thanks
    Regards

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: runtime error <vector>

    Try cerr instead of cout.

  3. #3
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: runtime error <vector>

    sorry wich aim? cerr << "problem "; print exactly the same thing; could you explain me waht you want say?.... ( I knnow at the end of slot() the vector are destroyed.......); the error is a memory read/write error
    thanks
    Regards

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: runtime error <vector>

    Quote Originally Posted by mickey
    the error is a memory read/write error
    I understood that it doesn't print "END problem". Post the exact error message.

  5. #5
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: runtime error <vector>

    nothing error in console; my windows isn't english so I try to traslate you:
    1. appear a first message that ask if you want send the problem to microsoft (without specify kind of problem)
    2. one message that say:
    the istruction "0x7c92103c" has referred to memory at "0x000801b3". The memory couldn't be "written". Click on "ok" to close application
    I'm sorry the problem isn't there: I comment all slot() and now I can call it 5 times, after same error; do anyone suggest me what it can be? Or how do I can find it? thanks
    Last edited by jacek; 22nd July 2006 at 16:54. Reason: changed [ code ] to [ quote ] to allow wrapping of long lines
    Regards

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: runtime error <vector>

    Quote Originally Posted by mickey
    Or how do I can find it?
    Run you application from a debugger and see the stack trace --- it should show you where the problem is.

  7. #7
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: runtime error <vector>

    Quote Originally Posted by mickey
    Right?
    Qt Code:
    1. vector <GLfloat*> ppp;
    2. for (int g=0; g < ....; g++) {
    3. GLfloat* position = new GLfloat[4];
    4. for (int i=0; i<4; i++) {
    5. position[i] = ch.toInt(); // split a string as "1543"
    6. }
    7. ppp.push_back(position);
    8. }
    9.  
    10. for( std::vector<GLfloat*>::iterator i = ppp.begin(); i != ppp.end(); ++i ) {
    11. delete [] *i;
    12. }
    13. ppp.clear();
    To copy to clipboard, switch view to plain text mode 
    and how obtain value of fist element array of first element vector?? thanks
    hi; the problem seems the delete for of this vector; if I comment it, it don't crash; is there anything wrong ? thanks
    Regards

  8. #8
    Join Date
    Aug 2006
    Location
    Nürnberg
    Posts
    7
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: runtime error <vector>

    Hej,

    You're right, this is the problem.
    Try "i++" instead of "++i" in line 10.

    If you use ++i, the value in i will be incremented before the body of the loop is executed, leading to a delete with invalid parameter. In fact it is the "*i" in the last call that causes the crash (it is always the last one ).

    You could in those cases increment the iterator in the body of the loop, then you have absolute control what happens why. This is for paranoids - like me

    Jan

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: runtime error <vector>

    Quote Originally Posted by helcaraxe
    If you use ++i, the value in i will be incremented before the body of the loop is executed
    No, it won't.

  10. #10
    Join Date
    Aug 2006
    Location
    Nürnberg
    Posts
    7
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: runtime error <vector>

    Then the problem is not in this code snippet

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: runtime error <vector>

    Quote Originally Posted by helcaraxe
    Then the problem is not in this code snippet
    Yes, that's why a stack trace is necessary. The memory might be deleted twice or accessed after it was deallocated.

Similar Threads

  1. runtime error
    By mickey in forum General Programming
    Replies: 1
    Last Post: 11th June 2006, 13:38
  2. QSA: loading scripts at runtime
    By seneca in forum Qt Programming
    Replies: 0
    Last Post: 15th February 2006, 15:19
  3. Replies: 4
    Last Post: 17th January 2006, 17:46
  4. Apache Portable Runtime
    By sumsin in forum General Discussion
    Replies: 0
    Last Post: 17th January 2006, 09:37
  5. runtime libraries?
    By fwohlfert in forum Newbie
    Replies: 1
    Last Post: 5th January 2006, 18:12

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.