Results 1 to 3 of 3

Thread: QTcpServer + QThread

  1. #1
    Join Date
    Feb 2008
    Location
    Russia, Moscow
    Posts
    35
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question QTcpServer + QThread

    Hi 2 all.
    I have a small problem. Now I make my personal HTTP server and I have some trouble with developing.

    There are sources of it: http://alexsnet.ru/temp/HTTPServ.zip

    When I compile - all is good, but when I connect to it debugger writes:
    QObject: Cannot create children for a parent that is in a different thread.
    (Parent is QTcpSocket(0x5716b8), parent's thread is QThread(0x509c80), current thread is sockThread(0x5716b0)

    How I can solve this problem?

  2. #2
    Join Date
    Feb 2008
    Location
    Russia, Moscow
    Posts
    35
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTcpServer + QThread

    Problem solved. But I have another one...

    How to explode (as in php) QByteArray by "\n" (endl);

    Qt Code:
    1. sockThread::sockThread(int socketDescriptor, QObject *parent)
    2. : QThread(parent), socketDescriptor(socketDescriptor)
    3. {
    4. }
    5.  
    6. void sockThread::run()
    7. {
    8. QTcpSocket tcpSocket;
    9. if (! tcpSocket.setSocketDescriptor(socketDescriptor) ) {
    10. emit error(tcpSocket.error());
    11. return;
    12. }
    13.  
    14. tcpSocket.waitForReadyRead();
    15.  
    16. QByteArray request = tcpSocket.readAll(); // HTTP request headers from client browser
    17.  
    18. QByteArray response;
    19. response.append( request );
    20.  
    21. tcpSocket.write( response );
    22. tcpSocket.disconnectFromHost();
    23. tcpSocket.waitForDisconnected();
    24. }
    To copy to clipboard, switch view to plain text mode 

    And also one question: can I recieve request headers by line to line?

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: QTcpServer + QThread

    1. QString::split().

    2. No, a TCP connection is a stream of bytes. But you can buffer the incoming data and read it line by line as next lines are ready.
    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.


Similar Threads

  1. QTcpSocket, QTcpServer problem
    By frido in forum Qt Programming
    Replies: 3
    Last Post: 3rd April 2009, 23:16
  2. QThread and QTcpSocket
    By ^NyAw^ in forum Qt Programming
    Replies: 3
    Last Post: 12th May 2008, 13:06
  3. QThread + QTcpServer
    By Fastman in forum Qt Programming
    Replies: 4
    Last Post: 19th July 2007, 16:19
  4. QThread exec proplem to stop...
    By patrik08 in forum Qt Programming
    Replies: 29
    Last Post: 21st May 2007, 07:51
  5. Is it possible to create a QThread without inheriting ?
    By probine in forum Qt Programming
    Replies: 6
    Last Post: 23rd March 2006, 22:51

Tags for this Thread

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.