I've made a client which can connect to a server, and it sends information to the server when a key is pressed (it's not a keylogger ), and the data that gets sent back to the client with the readyRead slot is needed in a different class than the dialog class. Is there any simple way that I can move the data from one class to another without passing the ui as a parameter through lots of functions (and possibly causing lag)?
I have 2 classes: Dialog and clientSocket. The dialog class has a private pointer to a clientSocket object. In the dialog class, I have overridden the keyPressEvent function to send the key presses to the server, which sends back a number in the clientSocket class. This is what I need in the dialog class.
keyPressEvent function in dialog.cpp:
void Dialog
::keyPressEvent(QKeyEvent *event
){ if(socketTest->connectedToClient()){ //if connected, let the server handle input.
char a[1];
sprintf(a, "%c", event->key());
socketTest->socket->write(a); //socketTest is a pointer to a clientSocket object, socket is a QTcpSocket in the clientSocket class
}
//stuff
void Dialog::keyPressEvent(QKeyEvent *event){
if(socketTest->connectedToClient()){ //if connected, let the server handle input.
char a[1];
sprintf(a, "%c", event->key());
socketTest->socket->write(a); //socketTest is a pointer to a clientSocket object, socket is a QTcpSocket in the clientSocket class
}
//stuff
To copy to clipboard, switch view to plain text mode
Server sends back "0", which is picked up in the readyRead function
void clientSocket::readyRead(){
//what I need to do here is call a function from the dialog class
}
void clientSocket::readyRead(){
QByteArray data = socket->readAll();
//what I need to do here is call a function from the dialog class
}
To copy to clipboard, switch view to plain text mode
Thanks for any help.
Bookmarks