Results 1 to 2 of 2

Thread: QTcpSocket.readLine causing segmentation failure

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2010
    Posts
    12
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Question QTcpSocket.readLine causing segmentation failure

    i am using QTcpsocket.readLine to read from a socket in a thread. it is working well otherwise but causing a segmentation failure. this the code:

    Header file
    Qt Code:
    1. #ifndef CLIENTTHREAD_H
    2. #define CLIENTTHREAD_H
    3. #include<QtNetwork/QTcpSocket>
    4. #include<QThread>
    5.  
    6. class clientThread:public QThread
    7. {
    8. Q_OBJECT
    9. public:
    10. clientThread(QTcpSocket *,QObject *,QString);
    11. // MainWindow *m;
    12. // int index;
    13. QString name;
    14. void run();
    15. signals:
    16. void updatechat(QString,QString);
    17. private slots:
    18. void readFromClient();
    19. private:
    20. QTcpSocket *socket;
    21. };
    22.  
    23. #endif // CLIENTTHREAD_H
    To copy to clipboard, switch view to plain text mode 
    Source File;

    Qt Code:
    1. #include "clientthread.h"
    2.  
    3. clientThread::clientThread(QTcpSocket *_socket,QObject *parent,/*int _index*/QString _name):QThread(parent),
    4. socket(_socket),name(_name)
    5. {
    6. connect(socket,SIGNAL(disconnected()),this,SLOT(terminate()));
    7. }
    8.  
    9. void clientThread::run(){
    10.  
    11. char *data;
    12. uint i;
    13. i=1024;
    14. qDebug()<<"client thread started";
    15.  
    16. }
    17.  
    18. void clientThread::readFromClient(){
    19. char *data;
    20. uint i;
    21. i=1024;
    22. [COLOR="Red"] socket->readLine(data,i);[/COLOR]
    23. emit updatechat(tr(data),name);
    24. }
    To copy to clipboard, switch view to plain text mode 
    Any Ideas why this is happening.
    Please help
    Last edited by hasnain; 4th September 2010 at 11:24. Reason: reformatted to look better

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QTcpSocket.readLine causing segmentation failure

    char *data;
    socket->readLine(data,i);
    Of course this crashes. What does data point to?

Similar Threads

  1. Readline from a particular index
    By giusepped in forum Qt Programming
    Replies: 5
    Last Post: 30th April 2010, 20:58
  2. QBuffer::readLine()
    By vfernandez in forum Qt Programming
    Replies: 2
    Last Post: 23rd April 2010, 20:57
  3. readLine in QProcess
    By grisson in forum Qt Programming
    Replies: 7
    Last Post: 15th October 2009, 17:39
  4. Reading non-ASCII lines from QTcpSocket via readLine()
    By joshtn in forum Qt Programming
    Replies: 1
    Last Post: 26th June 2008, 23:52
  5. Program hangs up in QTcpSocket::readLine()
    By vfernandez in forum Qt Programming
    Replies: 4
    Last Post: 21st February 2007, 11:36

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.