Hello, I have 2 classes: MdiChild and ClientSocket. I need to call the method addlog() of MdiChild inside clientsocket.cpp.
The normal thing to do is to include mdichild.h inside clientsocket.cpp. But no, it doens't work on this case (or maybe I'm missing something). Please, paste a working code for me. I already wasted too much time on this basic problem.
Read my comments.

// mdichild.h
Qt Code:
  1. #include <QtGui>
  2. #include "ui_mdichild.h"
  3. #include "clientsocket.h"
  4.  
  5. class MdiChild : public QDialog, private Ui::MdiChildDlg {
  6. Q_OBJECT
  7. Q_DISABLE_COPY(MdiChild)
  8. public:
  9. explicit MdiChild();
  10. virtual ~MdiChild();
  11. void addlog(QString text);
  12. private slots:
  13. void on_btConnect_clicked();
  14.  
  15. protected:
  16.  
  17. private:
  18. ClientSocket *clisock;
  19. };
  20.  
  21. #endif // MDICHILD_H
To copy to clipboard, switch view to plain text mode 

// mdichild.cpp
Qt Code:
  1. #include "mdichild.h"
  2. #include "ui_mdichild.h"
  3.  
  4. /**** I need to have access to this method from clientsocket.cpp ****/
  5. void MdiChild::addlog(QString text){
  6. if(!cbLogEvents->isChecked()) return;
  7. QTreeWidgetItem *item=new QTreeWidgetItem(twLogEvents);
  8. QTime time=QTime().currentTime();
  9.  
  10. item->setText(0,time.toString("hh:mm:ss"));
  11. item->setText(1,text);
  12.  
  13. twLogEvents->insertTopLevelItem(0,item);
  14. }
  15.  
  16. MdiChild::MdiChild()
  17. {
  18. static int clientsCount = 1;
  19. setupUi(this);
  20. setAttribute(Qt::WA_DeleteOnClose);
  21.  
  22. setWindowTitle(tr("Client %1 - ").arg(clientsCount++));
  23.  
  24. clisock = new ClientSocket(this);
  25. }
  26.  
  27. MdiChild::~MdiChild()
  28. {
  29. }
  30.  
  31. void MdiChild::on_btConnect_clicked()
  32. {
  33. if(btConnect->text()=="Connect"){
  34. addlog("Connecting to ("+ledRemoteHostIp->text()+":"+ledRemotePort->text()+") ...");
  35. clisock->connectToHost(ledRemoteHostIp->text(),ledRemotePort->text().toInt());
  36.  
  37. btConnect->setText("Disconnect");
  38. }
  39. else{
  40. addlog("Disconnecting from ("+ledRemoteHostIp->text()+":"+ledRemotePort->text()+") ...");
  41. clisock->abort();
  42. btConnect->setText("Connect");
  43. }
  44. }
To copy to clipboard, switch view to plain text mode 

// clientsocket.h
Qt Code:
  1. #ifndef CLIENTSOCKET_H
  2. #define CLIENTSOCKET_H
  3.  
  4. #include <QTcpSocket>
  5. #include <QSignalMapper>
  6. #include <QMessageBox>
  7.  
  8. class ClientSocket : public QTcpSocket
  9. {
  10. Q_OBJECT
  11. public:
  12. ClientSocket( QObject * parent = 0 );
  13. private:
  14. private slots:
  15. void OnConnected();
  16. };
  17.  
  18. #endif // CLIENTSOCKET_H
To copy to clipboard, switch view to plain text mode 

// clientsocket.cpp
Qt Code:
  1. #include "clientsocket.h"
  2.  
  3. ClientSocket::ClientSocket( QObject * parent)
  4. :QTcpSocket(parent)
  5. {
  6. connect(this,SIGNAL(connected()),this,SLOT(OnConnected()));
  7. }
  8.  
  9. void ClientSocket::OnConnected(){
  10. //** I need to be able to call addlog() here **
  11. //addlog("Connected to server!");
  12. }
To copy to clipboard, switch view to plain text mode