Results 1 to 14 of 14

Thread: Error message: The Application crashed

  1. #1
    Join Date
    Oct 2009
    Location
    Brazil Maceió/Alagoas
    Posts
    24
    Thanks
    7
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    Unix/X11 Windows

    Question Error message: The Application crashed

    Hello
    I created a small application using QTcpServer for sending remote messages when I compile using QT Creator in debug mode the application runs correctly.
    When I build configuring QT Creator to release the program crashes and is shown the following error message "image attached".

    I wrote a few lines: "qDebug () <<" msg ..."" in some parts of the program:

    ...
    qDebug() << "6. here OK "; far is correct, this message is displayed on the console

    if( msg == SAP_RETR_WELCOME_STRING) {
    }

    qDebug() << "7. here OK "; this message does not show in console

    if I try to print the contents of the msg variable, the program crashes:
    qDebug () << "contents of msg is. .." << msg;
    Attached Images Attached Images
    Last edited by josecarlosmissias; 4th December 2009 at 19:20.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Error message: The Application crashed

    Did you initialize this variable? What is its type anyway?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Oct 2009
    Location
    Brazil Maceió/Alagoas
    Posts
    24
    Thanks
    7
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    Unix/X11 Windows

    Default Re: Error message: The Application crashed

    The following definitions:
    ServerThread.h:
    Qt Code:
    1. ....
    2. private slots:
    3. void sendMessage(const QString &msg, const QVariant &data);
    4. void onReadyRead();
    5. void onMessage(const QString &msg, const QVariant &data);
    6. ....
    To copy to clipboard, switch view to plain text mode 

    ServerThread.cpp:

    Qt Code:
    1. void ServerThread::onReadyRead() {
    2. if (tcpSocket == NULL) return;
    3. if ( tcpSocket->state() != QAbstractSocket::ConnectedState ) return;
    4.  
    5. QDataStream in(tcpSocket);
    6. in.setVersion(QDataStream::Qt_4_5);
    7. if (blockSize == 0) {
    8. if (tcpSocket->bytesAvailable() < (int)sizeof(quint32)) return;
    9. in >> blockSize;
    10. reading_message = true;
    11. }
    12. if (tcpSocket->bytesAvailable() < blockSize) return;
    13. QString msgString;
    14. QVariant msgData;
    15. in >> msgString;
    16. in >> msgData;
    17.  
    18. emit onMessage( msgString, msgData );
    19. reading_message = false;
    20. blockSize = 0;
    21. if (tcpSocket->bytesAvailable() > 0) onReadyRead();
    22. }
    23.  
    24. void ServerThread::onMessage(const QString &msg, const QVariant &data )
    25. {
    26.  
    27. qDebug() << "6. here OK ";
    28.  
    29. if( msg == SAP_RETR_WELCOME_STRING)
    30. {
    31. }
    32. qDebug() << "7. here OK ";
    33.  
    34. ....
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Error message: The Application crashed

    QString (and most Qt classes) is not thread-safe - you can't access the same variable from different threads which you probably do bearing the fact that the thread object doesn't live in the same thread as its run() method. Your slots are executing in the context of the main thread - if you try to access any variables living in the worker thread from there, it is likely to lead to a crash.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Oct 2009
    Location
    Brazil Maceió/Alagoas
    Posts
    24
    Thanks
    7
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    Unix/X11 Windows

    Default Re: Error message: The Application crashed

    That's because I be going QString "msg" by reference?

    void onMessage (const QString & msg, const QVariant & data);

    how can I fix this?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Error message: The Application crashed

    The problem might not be with the string. It only reveals itself there. First you have to make sure you know which object lives where and which slot will be executed in which context. How does your run() method look like? Also please show the complete declaration of the thread class.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Oct 2009
    Location
    Brazil Maceió/Alagoas
    Posts
    24
    Thanks
    7
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    Unix/X11 Windows

    Default Re: Error message: The Application crashed

    the code can be attached. "zip"?
    Attached Files Attached Files

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Error message: The Application crashed

    Ok, after a quick look at your code....

    The thread object and all objects you create in its constructor do not live in the thread controlled by the object but in the thread in which the object was created. So your socket lives in the main thread and is handled by the main thread and not by your server thread. Move its creation to the run() method. When you do that, you will need a message loop running for the slots to activate. So run the exec() method from run() after you setup all objects - then you won't require that while loop. After you have cleaned up your code see if it still crashes and if so then come back and we'll continue investigating.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Oct 2009
    Location
    Brazil Maceió/Alagoas
    Posts
    24
    Thanks
    7
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    Unix/X11 Windows

    Question Re: Error message: The Application crashed

    Hi wysota,

    I found the reason why my program crashes, I'm loading a dll, when I comment the calls to the dll works in release mode. Do you have any tips on this it?
    I noticed that when I evoke a function of the DLL, the next line the values of the variables are affected, as if the values are lost.
    Last edited by josecarlosmissias; 9th December 2009 at 19:41.

  10. #10
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Error message: The Application crashed

    Sounds like memory corruption. Possibly wrong calling convention causing stack corruption.

  11. #11
    Join Date
    Oct 2009
    Location
    Brazil Maceió/Alagoas
    Posts
    24
    Thanks
    7
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    Unix/X11 Windows

    Question Re: Error message: The Application crashed

    Hi fatjuicymole,

    If I compile in debug mode works, just the fact of change to build in release mode, ready aborts.

  12. #12
    Join Date
    Oct 2009
    Location
    Brazil Maceió/Alagoas
    Posts
    24
    Thanks
    7
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    Unix/X11 Windows

    Question Re: Error message: The Application crashed

    Considering the explanation of fatjuicymole, follow the instructions of the development of the library in C attached, please could someone confirm me how to translate the types required in QT types. Eg:

    in C:
    Qt Code:
    1. typedef int (WINAPI *OpenDllECF) (BYTE *Ident, int porta, int veloc, LPSTR String);
    To copy to clipboard, switch view to plain text mode 

    I transcribed this for QT
    Qt Code:
    1. typedef int (*OpenDllPorta)(int porta,int veloc, char *str);
    To copy to clipboard, switch view to plain text mode 

    correct?
    Attached Files Attached Files

  13. #13
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Error message: The Application crashed

    You should leave the original definition alone so the compiler knows the calling convention (WINAPI) and appropriate parameters. You can't change it without also recompiling the library your calling. You also seem to be completely missing one parameter (Ident).

  14. The following user says thank you to squidge for this useful post:

    josecarlosmissias (10th December 2009)

  15. #14
    Join Date
    Oct 2009
    Location
    Brazil Maceió/Alagoas
    Posts
    24
    Thanks
    7
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    Unix/X11 Windows

    Default Re: Error message: The Application crashed

    Ok, solved.

Similar Threads

  1. QSkinWindows Classes
    By kernel_panic in forum Qt-based Software
    Replies: 45
    Last Post: 20th April 2010, 12:35
  2. Replies: 1
    Last Post: 8th November 2009, 12:49
  3. Deploying Qt 4.5.1 Application on RHEL 5.. Pls Help
    By swamyonline in forum Installation and Deployment
    Replies: 0
    Last Post: 28th June 2009, 11:43
  4. dll + application
    By fpujol in forum Qt Programming
    Replies: 11
    Last Post: 15th April 2007, 18:37

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.