Ok, I think I understand about dynamic allocation and using pointers, I try to use that, but still.. it doesn't solve my problem.

I declare CMsgSession *session on CMsgClient private member.
I write this on the constructor :

Qt Code:
  1. CMsgClient::CMsgClient()
  2. {
  3. session = new CMsgSession();
  4. }
To copy to clipboard, switch view to plain text mode 

And I declare QTcpSocket *tcpSocket on CMsgSession public member, I write this on the constructor :

Qt Code:
  1. CMsgSession::CMsgSession(QObject *parent) : QThread(parent), workerQuitFlag(false)
  2. {
  3. tcpSocket = new QTcpSocket();
  4. }
To copy to clipboard, switch view to plain text mode 

and I access the tcpSocket like this :

session->tcpSocket->write(buf, len);

it causes access violation, it's getting more confusing,
but thanks anyway..