Oh, sure.
I have this
@void MainWindow::establishConnection(){
tcpSocket->connectToHost("localhost", 5000);
}@
Which is called in my constructor.
I had
@establishConnection();@
without doing
@tcpSocket = new QTcpSocket(this);@
So far, using pointers has been really tripping me up, and tbh I'm still unsure of 75% of their use. I just know that in this case, it caused my program to crash without it.
And another question has come up. I've been trying at this for about two hours now, searching the forums and Google to no avail. All I'm trying to do is...
@...
connect(tcpServer, SIGNAL(newConnection()), this, SLOT(processConnection()));
}@
in a function called beginListening.
Whenever my client is opened, it immediately establishes a connection with the server, making processConnection run. k. Here's my processConnection function.
@// process new connections...
void MainWindow::processConnection(){
if (tcpServer->hasPendingConnections()){
onlinePlayers++;
//cout << onlinePlayers << endl;
player[onlinePlayers] = new QTcpSocket();
player[onlinePlayers] = tcpServer->nextPendingConnection();
addText(tr("New connection received from %1.")
.arg(player[onlinePlayers]->peerAddress().toIPv4Address()));
//testing junk
addText(player[onlinePlayers]->peerAddress().toString());
}
}@
in an attempt to display to the server that a new connection has indeed been accepted, and then I want to save that connection in my own defined array of QTcpSockets. So far, everything seems to go well until we get to the part where I'm trying to return the host connection's IP address. When I use the .toIPv4Address() call, it returns 0. When I use the toString() call, it returns a strange string "::1%0". Even did a Google search on that string, with no luck.