Results 1 to 12 of 12

Thread: error message appears when function is called

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

    Default error message appears when function is called

    An error message prompt appears when function, processInputData(param1, param2, ....) is called.
    The application exits when 'Don't Send' button on the message prompt is clicked on.
    How do I resolve this issue?

    Here is the code:
    Qt Code:
    1. New::New(QWidget *parent) :
    2. QDialog(parent)
    3. {
    4. okButton = createButton(tr("&OK"), SLOT(messageOk()));
    5.  
    6. createCMRFilesMessageGroupBox();
    7. createEDMessageGroupBox();
    8. createESMessageGroupBox();
    9.  
    10. createmainLayout();
    11.  
    12. setWindowTitle(tr("New Case"));
    13. resize(450, 100);
    14. }
    15. void New::messageOk()
    16. {
    17.  
    18. QMessageBox::about(this,tr("OK clicked"),tr("OK"));
    19. processInputData(endocardialfileName.toAscii(), //convert 'QString' to 'const char*'
    20. epicardialfileName.toAscii(), //convert 'QString' to 'const char*'
    21. 1,
    22. 1.1,
    23. 1.1,
    24. 1,
    25. 1.1,
    26. 1.1);
    27.  
    28.  
    29. }
    To copy to clipboard, switch view to plain text mode 

    Definition of processInputData( ):
    Qt Code:
    1. processInputData(const char*, const char* ,
    2. const int,
    3. const float, const float,
    4. const int,
    5. const float, const float );
    To copy to clipboard, switch view to plain text mode 
    Last edited by babygal; 11th June 2010 at 08:22.

  2. #2
    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: error message appears when function is called

    QString::toAscii() does not return a const char pointer.

  3. The following user says thank you to ChrisW67 for this useful post:

    babygal (14th June 2010)

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

    Default Re: error message appears when function is called

    How do I resolve the issue?

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

    Default Re: error message appears when function is called

    The error mentioned is as seen in the attachment. How do I resolve it quickly?
    I don't get any error when i compile. I am only getting this error during run time...:-(
    Attached Files Attached Files
    Last edited by babygal; 14th June 2010 at 08:08.

  6. #5
    Join Date
    Jun 2010
    Location
    India
    Posts
    50
    Thanks
    1
    Thanked 15 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: error message appears when function is called

    I cannot read your doc file. I suspect you may do the following which i guess from the previous reply..

    pInputdata=QString::toAscii() .data();

    I assume char* pInputData is a Function Argument. If this isn't right please show me what is in your error.doc file in plain text. If my assumption is right let me know. the solution is simple.

  7. The following user says thank you to agathiyaa for this useful post:

    babygal (14th June 2010)

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

    Default Re: error message appears when function is called

    The error is :
    Application.exe has encountered a problem and needs to close. We are sorry for the inconvenience.If you were in the middle of something, the information you were working on might be lost.

    Please tell Microsoft about this problem.We have created an error report that you can send to us. We will treat this report as confidential and anonymous. To see what data this error report contains, click here.

  9. #7
    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: error message appears when function is called

    You will get this generic catch-all error from the Windows system if you access a pointer that is invalid or you access more memory than you should through an otherwise valid pointer (and any number of other things). If something is expecting a pointer to a NUL terminated string (as your code is) and you pass something that is not a pointer to a NUL terminated string (as your code does) then this is often the result.

    You are passing a QByteArray where the code is expecting a const char*. You need to revisit lines 19 and 20 of your original post after reading the docs for QString::toAscii() and QByteArray::constData()

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

    babygal (14th June 2010)

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

    Default Re: error message appears when function is called

    Can you please show me clearly? I don't quite understand.
    Last edited by babygal; 14th June 2010 at 10:46.

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

    Default Re: error message appears when function is called

    Quote Originally Posted by agathiyaa View Post
    I cannot read your doc file. I suspect you may do the following which i guess from the previous reply..

    pInputdata=QString::toAscii() .data();

    I assume char* pInputData is a Function Argument. If this isn't right please show me what is in your error.doc file in plain text. If my assumption is right let me know. the solution is simple.
    Can you please show me clearly? I don't quite understand how to implement this way.

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

    Default Re: error message appears when function is called

    I solved the bug with the code below:

    1.
    Qt Code:
    1. processInputData(endocardialfileName.toAscii().constData(), epicardialfileName.toAscii().constData(), ....
    To copy to clipboard, switch view to plain text mode 

    Other 3 possible solutions I found :

    2.
    Qt Code:
    1. processInputData(endocardialfileName.toAscii().data(), epicardialfileName.toAscii().data(), ....
    To copy to clipboard, switch view to plain text mode 


    3.
    Qt Code:
    1. processInputData(endocardialfileName.toLatin1().constData(), epicardialfileName.toLatin1().constData(), ....
    To copy to clipboard, switch view to plain text mode 


    4.
    Qt Code:
    1. processInputData(endocardialfileName.toLatin1().data(), epicardialfileName.toLatin1().data(), ....
    To copy to clipboard, switch view to plain text mode 
    Last edited by babygal; 14th June 2010 at 11:04.

  14. #11
    Join Date
    Jun 2010
    Location
    India
    Posts
    50
    Thanks
    1
    Thanked 15 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: error message appears when function is called

    Good to know that you have solved the issue.

    But my recommendation is to use the following

    Qt Code:
    1. char end[MAX_PATH]={0};
    2. char epi[MAX_PATH]={0};
    3.  
    4. strcpy(end,endocardialfileName.toAscii().data());
    5. strcpy(epi,epicardialfileName.toAscii().data());
    6.  
    7. processInputData(end,epi,...);
    To copy to clipboard, switch view to plain text mode 

    Because toAscii().data() function uses internal stack which may not be valid all the time.

    Any Comments ???.

  15. #12
    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: error message appears when function is called

    The four options babygal pointed out should be safe because the scope of the temporary QByteArray in the:
    Qt Code:
    1. processInputData(endocardialfileName.toLatin1().constData(), ...
    To copy to clipboard, switch view to plain text mode 
    call extends to the completion of function processInputData() (the enclosing C++ statement). If the value could not be used immediately then you would have to make a persistent copy of it as above (using strncpy or a safer option though), or by making the QByteArray explicit so that you can control the scope:
    Qt Code:
    1. {
    2. ...
    3. QByteArray asciiFileName = endocardialfileName.toAscii();
    4. processInputData(asciiFileName.constData(), ...);
    5. // more uses of the ASCII string
    6. char *s = asciiFileName.data();
    7. somefunc(s);
    8. ...
    9. }
    To copy to clipboard, switch view to plain text mode 

  16. The following user says thank you to ChrisW67 for this useful post:

    agathiyaa (15th June 2010)

Similar Threads

  1. error message
    By offline in forum Qt Programming
    Replies: 1
    Last Post: 5th November 2009, 14:08
  2. wrong virtual function called at some events on MacOS?
    By akos.maroy in forum Qt Programming
    Replies: 0
    Last Post: 3rd July 2009, 11:06
  3. Public function called on MDISubWindow ignores code
    By ad5xj in forum Qt Programming
    Replies: 2
    Last Post: 24th February 2009, 16:29
  4. QString - no member function called 'find'
    By pitterb in forum Newbie
    Replies: 1
    Last Post: 13th January 2009, 11:31
  5. getting the error message when trying to run the application in QT
    By pallavi Boyapat in forum Qt Programming
    Replies: 49
    Last Post: 31st October 2008, 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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.