Results 1 to 6 of 6

Thread: QTcpSocket

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2010
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTcpSocket

    Quote Originally Posted by Fallen_ View Post
    Hi, can someone help me with this code?
    I don't know if it connects or anything it just doesnt write anything to the "QTextEdit* read"
    mainwindow.h
    Qt Code:
    1. connect(write, SIGNAL(textChanged(const QString&)), this, SLOT(sendMessage()));
    2. }
    To copy to clipboard, switch view to plain text mode 
    Hi,

    This part is problemmatic I guess. The signal and corresponding slot should have the same arguments. The connection should be like
    Qt Code:
    1. connect(write, SIGNAL(textChanged(QString)), this, SLOT(sendMessage(QString)));
    To copy to clipboard, switch view to plain text mode 

    Your slot should be declared as

    void sendMessage(const QString& dummy)

    I hope this solves your problem.

  2. #2
    Join Date
    Aug 2010
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTcpSocket

    The reason you cannot type to "TextEdit* read" is

    Qt Code:
    1. read->setReadOnly(true);
    To copy to clipboard, switch view to plain text mode 
    if you change the argument to "false", you will be able to write in the "read".

  3. #3
    Join Date
    Aug 2010
    Posts
    58
    Qt products
    Qt4
    Platforms
    Windows
    Thanked 2 Times in 2 Posts

    Default Re: QTcpSocket

    Quote Originally Posted by hkaraoguz84 View Post
    Hi,

    This part is problemmatic I guess. The signal and corresponding slot should have the same arguments. The connection should be like
    Qt Code:
    1. connect(write, SIGNAL(textChanged(QString)), this, SLOT(sendMessage(QString)));
    To copy to clipboard, switch view to plain text mode 

    Your slot should be declared as

    void sendMessage(const QString& dummy)

    I hope this solves your problem.
    my problem is that im not receiving anything from the socket & i need to be able to receive & send, this function:
    Qt Code:
    1. void MainWindow::appendToWindow()
    2. {
    3. char buffer[1024];
    4. while(socket->canReadLine()) {
    5. socket->readLine(buffer, sizeof(buffer));
    6. read->append(buffer);
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 
    Quote Originally Posted by hkaraoguz84 View Post
    The reason you cannot type to "TextEdit* read" is


    if you change the argument to "false", you will be able to write in the "read".
    i don't want to write here, this text edit is for receiving data from the socket ;/
    --
    edit:
    i made something like this:
    Qt Code:
    1. if(socket->waitForConnected(-1) == true)
    2. read->append("Connected.");
    3. else
    4. read->append(socket->errorString());
    To copy to clipboard, switch view to plain text mode 
    it gave me this:
    Qt Code:
    1. Socket operation timed out
    To copy to clipboard, switch view to plain text mode 
    Last edited by Fallen_; 25th August 2010 at 00:04.

  4. #4
    Join Date
    Aug 2010
    Posts
    58
    Qt products
    Qt4
    Platforms
    Windows
    Thanked 2 Times in 2 Posts

    Default Re: QTcpSocket

    bump.........

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

    Default Re: QTcpSocket

    The textChanged signal is fired every time you press a key. This might not be the behaviour you want.

    Use the readyRead() signal of the socket and connect it to your appendToWindow() slot.

    By the way, if a socket times out, that's in most cases not a problem with your code.

Similar Threads

  1. Need Help with QTcpSocket
    By jknotzke in forum Qt Programming
    Replies: 2
    Last Post: 25th October 2009, 14:55
  2. QTcpSocket help
    By tsd-charlie in forum Newbie
    Replies: 1
    Last Post: 6th August 2009, 20:40
  3. Using QTcpSocket
    By mraittin in forum Qt Programming
    Replies: 1
    Last Post: 2nd September 2007, 10:54
  4. QTcpSocket and Qt 4.2.3
    By slcotter in forum Qt Programming
    Replies: 4
    Last Post: 9th May 2007, 17:14
  5. QT4.2.2 and QTcpSocket
    By Nyphel in forum Qt Programming
    Replies: 13
    Last Post: 11th March 2007, 12:30

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.