Results 1 to 6 of 6

Thread: Crash of the Server Application

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2012
    Posts
    232
    Thanks
    118
    Thanked 18 Times in 10 Posts
    Platforms
    Windows Android

    Default Crash of the Server Application

    Hi,

    When I connect with the Server Application I receive the Crash Error on the line:

    Qt Code:
    1. if( !socket->setSocketDescriptor( m_descriptor ) )
    To copy to clipboard, switch view to plain text mode 

    Please run the project "ServerTimer" than run "ViewerServerTimer" and click the button "Connect"

    ServerTimer.pro
    Qt Code:
    1. QT += core
    2. QT += network
    3. QT -= gui
    4.  
    5. TARGET = ServerTimer
    6. CONFIG += console
    7. CONFIG -= app_bundle
    8.  
    9. TEMPLATE = app
    10.  
    11.  
    12. SOURCES += main.cpp \
    13. server.cpp \
    14. serverthread.cpp
    15.  
    16. HEADERS += \
    17. server.h \
    18. serverthread.h
    To copy to clipboard, switch view to plain text mode 

    server.h
    Qt Code:
    1. #ifndef SERVER_H
    2. #define SERVER_H
    3.  
    4. #include <QTcpServer>
    5. #include "serverthread.h"
    6.  
    7. class Server : public QTcpServer
    8. {
    9. public:
    10. Server();
    11.  
    12. protected:
    13. void incomingConnection(int descriptor);
    14.  
    15. private:
    16. ServerThread *thread;
    17. };
    18.  
    19. #endif // SERVER_H
    To copy to clipboard, switch view to plain text mode 

    server.cpp
    Qt Code:
    1. #include "server.h"
    2.  
    3. Server::Server() : QTcpServer()
    4. {
    5. }
    6.  
    7. void Server::incomingConnection( int descriptor )
    8. {
    9. thread = new ServerThread( descriptor, this );
    10.  
    11. connect( thread, SIGNAL(finished()), thread, SLOT(deleteLater()) );
    12. thread->start();
    13. }
    To copy to clipboard, switch view to plain text mode 

    serverthread.h
    Qt Code:
    1. #ifndef SERVERTHREAD_H
    2. #define SERVERTHREAD_H
    3.  
    4. #include <QThread>
    5. #include <QTimer>
    6. #include <QTcpSocket>
    7.  
    8. class ServerThread : public QThread
    9. {
    10. public:
    11. ServerThread( int descriptor, QObject *parent );
    12.  
    13. void run();
    14.  
    15. public slots:
    16. void sendData();
    17.  
    18. private:
    19. int m_descriptor;
    20.  
    21. private:
    22. QTimer *timer;
    23. QTcpSocket *socket;
    24. };
    25.  
    26. #endif // SERVERTHREAD_H
    To copy to clipboard, switch view to plain text mode 

    serverthread.cpp
    Qt Code:
    1. #include "serverthread.h"
    2.  
    3. ServerThread::ServerThread( int descriptor, QObject *parent ) : QThread( parent )
    4. {
    5. m_descriptor = descriptor;
    6. }
    7.  
    8. void ServerThread::run()
    9. {
    10. if( !socket->setSocketDescriptor( m_descriptor ) )
    11. {
    12. qDebug( "Socket error!" );
    13. return;
    14. }
    15.  
    16. timer = new QTimer;
    17. connect(timer, SIGNAL(timeout()), this, SLOT(sendData()));
    18. timer->start(1000);
    19. }
    20.  
    21. void ServerThread::sendData() {
    22. //socket->write( "data" );
    23. }
    To copy to clipboard, switch view to plain text mode 

    main.cpp
    Qt Code:
    1. #include <QCoreApplication>
    2. #include "server.h"
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QCoreApplication a(argc, argv);
    7.  
    8. Server server;
    9. if( !server.listen( QHostAddress::Any, 1234 ) )
    10. {
    11. qCritical( "Cannot listen to port 1234." );
    12. return 1;
    13. }
    14.  
    15. return a.exec();
    16. }
    To copy to clipboard, switch view to plain text mode 

    Thank you
    Attached Files Attached Files

Similar Threads

  1. how to avoid crash of my application......
    By newb in forum Qt Programming
    Replies: 1
    Last Post: 30th August 2010, 10:09
  2. application crash problem
    By anshul in forum Newbie
    Replies: 3
    Last Post: 25th December 2009, 12:27
  3. Application crash in Vista
    By yj... in forum Installation and Deployment
    Replies: 1
    Last Post: 5th June 2009, 08:18
  4. Weird application crash
    By MarkoSan in forum Qt Programming
    Replies: 10
    Last Post: 20th May 2008, 14:13
  5. Replies: 5
    Last Post: 24th April 2006, 15:42

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.