QTcpSocket problem



  • Hello guys...
    I have to mention that I'm new to Qt. Now I am trying to develop an interface for a Chess Game Client. The problem is the following...I have a login dialog, that gets input from the user, the address, and the port. With that information, I created a QTcpSocket, which was used to connect to the host. But, my problem is that, I have a main window that need that socket in order to communicate with the server. How can I do this. Also, if someone can offer some advices in creating the Chess Game.
    Thanks



  • probably something like this:

    declaration in your *.h file:
    @
    class YourChessDialog : public QDialog
    {
    ...
    private slots:
    void connectToServer();
    ...
    QTcpSocket tcpSocket;
    ...
    };
    @
    definition in your *.cpp file:
    @
    void YourChessDialog::connectToServer()
    {
    tcpSocket.connectToHost("your_internet_address", your_port_number);
    // ie: "chessserver.com", 2345
    }
    @
    And don't forget to close your connection.



  • Thanks, broadpeak, I will try what you gaved me.



  • This is for login dialog, but for connecting the socket, to the other dialog? I mean, yea, this looks similar to what I have in the login dialog, but how to connect, the resulting socket, from this, to the second dialog? Thanks alot.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.