// header which uses qurloperator
#ifndef FILEREADER_H
#define FILEREADER_H
#include "FileReader_.h"
class QUrlOperator;
class QNetworkOperation;
class FileReader : public FileReader_
{
Q_OBJECT
public:
FileReader
(QWidget* parent
= 0,
const char* name
= 0, WFlags fl
= 0 );
~FileReader();
public slots:
void stateChangedSlot(int state,const QString&);
void finishedSlot(QNetworkOperation *operation);
private:
QUrlOperator* m_op;
};
#endif
// qurloperator using class's imp.
#include <qurloperator.h>
#include <qnetwork.h>
#include <iostream>
#include "filereader.h"
using namespace std;
FileReader
::FileReader(QWidget* parent,
const char* name, WFlags fl
): FileReader_(parent,name,fl)
{
// host part of url, which is here asdfasdf, should be unreachable. So host should not exist on network
m_op = new QUrlOperator("http://asdfasdf/asdf/abcd.php");
connect(m_op, SIGNAL(connectionStateChanged(int,const QString&)), SLOT(stateChangedSlot(int,const QString&)));
connect( m_op, SIGNAL(finished(QNetworkOperation*)), SLOT(finishedSlot(QNetworkOperation*)));
m_op->get();
}
void FileReader::stateChangedSlot(int state,const QString& data)
{
cout << "conn state changed to: " << data.ascii() << endl;
switch( state ){
case QNetworkProtocol::ConConnected:
cout << "CONNECTED" << endl;
break;
case QNetworkProtocol::ConClosed:
cout << "CONNECTION CLOSED" << endl;
break;
}
}
void FileReader::finishedSlot(QNetworkOperation *operation)
{
switch( operation->operation() ){
case QNetworkProtocol::OpGet:
if ( operation->state() == QNetworkProtocol::StFailed ) {
cerr << "finished but there is an error..." << endl;
}
else if ( operation->state() == QNetworkProtocol::StDone ) {
cout << "connection successfully finished..." << endl;
}
}
close(true);
}
FileReader::~FileReader()
{
delete m_op;
}
// header of opening widget
#ifndef MAINUI_H
#define MAINUI_H
#include "MainUI_.h"
class FileReader;
class MainUI : public Form1
{
Q_OBJECT
public:
MainUI
(QWidget* parent
= 0,
const char* name
= 0, WFlags fl
= 0 );
public slots:
void refreshInfo();
protected:
FileReader* fileReader;
};
#endif
// imp.
#include <qtimer.h>
#include "mainui.h"
#include "filereader.h"
MainUI
::MainUI(QWidget* parent,
const char* name, WFlags fl
): Form1(parent,name,fl)
{
connect(m_timer, SIGNAL(timeout()), SLOT(refreshInfo()));
m_timer->start( 30000 );
fileReader = new FileReader();
fileReader->show();
}
void MainUI::refreshInfo()
{
fileReader = new FileReader();
fileReader->show();
}
// main.cpp
#include <qapplication.h>
#include <qnetwork.h>
#include <stdio.h>
#include <stdlib.h>
#include "mainui.h"
int main(int argc, char *argv[])
{
qInitNetworkProtocols();
MainUI fr;
app.setMainWidget( &fr );
fr.show();
app.exec();
}
// header which uses qurloperator
#ifndef FILEREADER_H
#define FILEREADER_H
#include "FileReader_.h"
class QUrlOperator;
class QNetworkOperation;
class FileReader : public FileReader_
{
Q_OBJECT
public:
FileReader(QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
~FileReader();
public slots:
void stateChangedSlot(int state,const QString&);
void finishedSlot(QNetworkOperation *operation);
private:
QUrlOperator* m_op;
};
#endif
// qurloperator using class's imp.
#include <qurloperator.h>
#include <qnetwork.h>
#include <iostream>
#include "filereader.h"
using namespace std;
FileReader::FileReader(QWidget* parent, const char* name, WFlags fl)
: FileReader_(parent,name,fl)
{
// host part of url, which is here asdfasdf, should be unreachable. So host should not exist on network
m_op = new QUrlOperator("http://asdfasdf/asdf/abcd.php");
connect(m_op, SIGNAL(connectionStateChanged(int,const QString&)), SLOT(stateChangedSlot(int,const QString&)));
connect( m_op, SIGNAL(finished(QNetworkOperation*)), SLOT(finishedSlot(QNetworkOperation*)));
m_op->get();
}
void FileReader::stateChangedSlot(int state,const QString& data)
{
cout << "conn state changed to: " << data.ascii() << endl;
switch( state ){
case QNetworkProtocol::ConConnected:
cout << "CONNECTED" << endl;
break;
case QNetworkProtocol::ConClosed:
cout << "CONNECTION CLOSED" << endl;
break;
}
}
void FileReader::finishedSlot(QNetworkOperation *operation)
{
switch( operation->operation() ){
case QNetworkProtocol::OpGet:
if ( operation->state() == QNetworkProtocol::StFailed ) {
cerr << "finished but there is an error..." << endl;
}
else if ( operation->state() == QNetworkProtocol::StDone ) {
cout << "connection successfully finished..." << endl;
}
}
close(true);
}
FileReader::~FileReader()
{
delete m_op;
}
// header of opening widget
#ifndef MAINUI_H
#define MAINUI_H
#include "MainUI_.h"
class QTimer;
class FileReader;
class MainUI : public Form1
{
Q_OBJECT
public:
MainUI(QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
public slots:
void refreshInfo();
protected:
QTimer* m_timer;
FileReader* fileReader;
};
#endif
// imp.
#include <qtimer.h>
#include "mainui.h"
#include "filereader.h"
MainUI::MainUI(QWidget* parent, const char* name, WFlags fl)
: Form1(parent,name,fl)
{
m_timer = new QTimer(this);
connect(m_timer, SIGNAL(timeout()), SLOT(refreshInfo()));
m_timer->start( 30000 );
fileReader = new FileReader();
fileReader->show();
}
void MainUI::refreshInfo()
{
fileReader = new FileReader();
fileReader->show();
}
// main.cpp
#include <qapplication.h>
#include <qnetwork.h>
#include <stdio.h>
#include <stdlib.h>
#include "mainui.h"
int main(int argc, char *argv[])
{
QApplication app(argc,argv);
qInitNetworkProtocols();
MainUI fr;
app.setMainWidget( &fr );
fr.show();
app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks