eleanor
29th October 2007, 20:52
I'm curious, why doesn't this program work:
MAIN.CPP
#include <QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
CMainWindow window;
window.show();
//return app.exec();
}
MAINWINDOW.H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
/**
@author eleanor <eleanor@localhost>
*/
#include <QWidget>
#include <QString>
#include <QTextStream>
#include <QTcpSocket>
#include <QAbstractSocket>
#include <QLabel>
class CMainWindow : public QWidget {
public:
CMainWindow(QWidget *parent=0);
~CMainWindow();
private:
QTcpSocket *m_pSocket;
};
#endif
MAINWINDOW.CPP
#include "mainwindow.h"
CMainWindow::CMainWindow(QWidget *parent) : QWidget(parent) {
//creating a socket
m_pSocket = new QTcpSocket(this);
QString myHost("www.google.com");
int myPort = 80;
//this function establishes connection and returns immediately
m_pSocket->connectToHost(myHost, myPort);
QString input = "GET /index.php HTTP/1.1\n\n";
if(m_pSocket->state() == QAbstractSocket::ConnectedState) {
QTextStream stream(m_pSocket);
stream << input;
}
QString text;
while(m_pSocket->canReadLine()) {
text += m_pSocket->readLine();
}
QTextStream output(stdout);
QString enteredCommand = text;
output >> text;
}
CMainWindow::~CMainWindow() {
}
I would appreciate any tips. Thanks
MAIN.CPP
#include <QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
CMainWindow window;
window.show();
//return app.exec();
}
MAINWINDOW.H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
/**
@author eleanor <eleanor@localhost>
*/
#include <QWidget>
#include <QString>
#include <QTextStream>
#include <QTcpSocket>
#include <QAbstractSocket>
#include <QLabel>
class CMainWindow : public QWidget {
public:
CMainWindow(QWidget *parent=0);
~CMainWindow();
private:
QTcpSocket *m_pSocket;
};
#endif
MAINWINDOW.CPP
#include "mainwindow.h"
CMainWindow::CMainWindow(QWidget *parent) : QWidget(parent) {
//creating a socket
m_pSocket = new QTcpSocket(this);
QString myHost("www.google.com");
int myPort = 80;
//this function establishes connection and returns immediately
m_pSocket->connectToHost(myHost, myPort);
QString input = "GET /index.php HTTP/1.1\n\n";
if(m_pSocket->state() == QAbstractSocket::ConnectedState) {
QTextStream stream(m_pSocket);
stream << input;
}
QString text;
while(m_pSocket->canReadLine()) {
text += m_pSocket->readLine();
}
QTextStream output(stdout);
QString enteredCommand = text;
output >> text;
}
CMainWindow::~CMainWindow() {
}
I would appreciate any tips. Thanks