Hi, can someone help me with this code?
I don't know if it connects or anything it just doesnt write anything to the "QTextEdit* read"
mainwindow.h
Qt Code:
  1. #ifndef MAINWINDOW_H
  2. #define MAINWINDOW_H
  3.  
  4. #include <QDialog>
  5. #include <QTcpSocket>
  6.  
  7. class QLineEdit;
  8. class QLabel;
  9. class QTextEdit;
  10.  
  11. class MainWindow : public QDialog
  12. {
  13. Q_OBJECT
  14. public:
  15. MainWindow(QWidget* parent = 0);
  16.  
  17. public slots:
  18. void Connect();
  19. void appendToWindow();
  20. void sendMessage();
  21.  
  22. private:
  23. QLabel *ipLabel, *portLabel;
  24. QPushButton *done, *quit;
  25. QLineEdit *ipLine, *portLine, *write;
  26. QTcpSocket *socket;
  27. QTextEdit *read;
  28. };
  29. #endif
To copy to clipboard, switch view to plain text mode 
mainwindow.cpp
Qt Code:
  1. #include "mainwindow.h"
  2. #include <QtGui>
  3. #include <QtNetwork>
  4.  
  5. MainWindow::MainWindow(QWidget* parent)
  6. : QDialog(parent)
  7. {
  8. socket = new QTcpSocket(this);
  9. ipLabel = new QLabel(tr("<i><font color=red>IP:</font></i>"));
  10. portLabel = new QLabel(tr("<i><font color=red>Port:</font></i>"));
  11. done = new QPushButton(tr("Connect"));
  12. quit = new QPushButton(tr("Quit"));
  13. ipLine = new QLineEdit;
  14. portLine = new QLineEdit;
  15. write = new QLineEdit;
  16. read = new QTextEdit;
  17.  
  18. read->setReadOnly(true);
  19.  
  20. QVBoxLayout* layout = new QVBoxLayout;
  21. layout->addWidget(ipLabel);
  22. layout->addWidget(ipLine);
  23. layout->addWidget(portLabel);
  24. layout->addWidget(portLine);
  25.  
  26. QVBoxLayout* layout2 = new QVBoxLayout;
  27. layout2->addWidget(done);
  28. layout2->addWidget(quit);
  29.  
  30. QVBoxLayout* layout3 = new QVBoxLayout;
  31. layout3->addWidget(write);
  32. layout3->addWidget(read);
  33.  
  34. QHBoxLayout* mainLayout = new QHBoxLayout;
  35. mainLayout->addLayout(layout);
  36. mainLayout->addLayout(layout2);
  37. mainLayout->addLayout(layout3);
  38. setLayout(mainLayout);
  39.  
  40. connect(done, SIGNAL(clicked()), this, SLOT(Connect()));
  41. connect(quit, SIGNAL(clicked()), this, SLOT(close()));
  42. connect(done, SIGNAL(clicked()), this, SLOT(appendToWindow()));
  43. connect(write, SIGNAL(textChanged(const QString&)), this, SLOT(sendMessage()));
  44. }
  45.  
  46. void MainWindow::Connect()
  47. {
  48. qint16 port;
  49. QString host;
  50. if(ipLine->text().isEmpty())
  51. return;
  52.  
  53. if(portLine->text().isEmpty())
  54. port = 6667;
  55.  
  56. host = ipLine->text();
  57. socket->connectToHost(host, port);
  58. }
  59.  
  60. void MainWindow::appendToWindow()
  61. {
  62. char buffer[1024];
  63. while(socket->canReadLine()) {
  64. socket->readLine(buffer, sizeof(buffer));
  65. read->append(buffer);
  66. }
  67. }
  68.  
  69. void MainWindow::sendMessage()
  70. {
  71. if(write->text().isEmpty())
  72. return;
  73.  
  74. socket->write(write->text().toLatin1());
  75. }
To copy to clipboard, switch view to plain text mode 
main.cpp
Qt Code:
  1. #include "mainwindow.h"
  2. #include <QApplication>
  3.  
  4. int main(int argc, char *argv[])
  5. {
  6. QApplication a(argc, argv);
  7. MainWindow w;
  8. w.show();
  9. w.resize(200, 200);
  10. return a.exec();
  11. }
To copy to clipboard, switch view to plain text mode 
Any help is appreciated.