Results 1 to 12 of 12

Thread: Adding nonQt classes to QtApplication

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Adding nonQt classes to QtApplication

    Ok, here is your mistake, in file Automat.cpp:

    Qt Code:
    1. Automat::Automat()
    2. {
    3. _maxStAkcij=MAX_AKC;
    4. _verAkcije= new double(_maxStAkcij);
    5. //_verAkcije= (double *)malloc(_maxStAkcij);
    6.  
    7. for(int i=0; i < _maxStAkcij; i++)
    8. _verAkcije[i]=1/(float)_maxStAkcij;
    9.  
    10. _kazen = KAZEN;
    11. _nagrada = NAGRADA;
    12. }
    To copy to clipboard, switch view to plain text mode 
    The line:
    Qt Code:
    1. _verAkcije= new double(_maxStAkcij);
    To copy to clipboard, switch view to plain text mode 
    is causing your crash, because will create only ONE double and will assign _maxStAkcij value to it. It crashed in the next for loop, when you populate the array. It will cause a buffer overrun in your array.

    You have to use square brackets to allocate an array. Like this:
    Qt Code:
    1. _verAkcije= new double[_maxStAkcij];
    To copy to clipboard, switch view to plain text mode 
    Try it and it will work.

    Regards
    Last edited by marcel; 23rd April 2007 at 21:04.

  2. The following user says thank you to marcel for this useful post:

    codebehind (23rd April 2007)

  3. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Adding nonQt classes to QtApplication

    I actually don't have Qt3 installed, so I couldn't properly test your code. But I am almost certain that is the error.

    Regards

  4. #3
    Join Date
    Apr 2007
    Posts
    76
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Adding nonQt classes to QtApplication

    It works fine. thx again!

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.