PDA

View Full Version : errors while upload files on http server????



sups
23rd February 2011, 04:10
Hi,

I tried below given code for uploading files on http server which was posted on the forum.But it is giving some errors.plz help me to remove them out.
Iam not able to understand what the error is..plz help me urgently.




#include "http.h"
void HttpGet :: postfile()
{
int i = 0;

QString filename;

QString files = QFileDialog::getOpenFileName(this, tr("Select File"),"D://");

if (files.isEmpty())

return;

file = new QFile(filename);

Q_ASSERT(file != NULL);
if(!file->open(QIODevice::ReadWrite))

{

qDebug() << "opern err" << file->fileName();

return;

}

qDebug() << "Upload strat";
http->put(file,filename);
qDebug() << "Upload end";
}



The errors after running program are.

1)error: no matching function for call to ‘QFileDialog::getOpenFileName(HttpGet* const, QString, const char [5])’
2)14: error: no match for ‘operator=’ in ‘((HttpGet*)this)->HttpGet::file = (operator new(8u), (<statement>, ((QFile*)<anonymous>)))’
3)16: error: no match for ‘operator!=’ in ‘((HttpGet*)this)->HttpGet::file != 0’

mcosta
23rd February 2011, 10:07
The answers of error are:

1) HttpGet is not inherited from QWidget;

2) You MUST inckude <QFile>

3) file is a memmer of HttpGet and isn't a QFile*;

Post your Header

sups
24th February 2011, 12:01
i tried as per ur reply.but there is an error
error: ‘class QHttp’ has no member named ‘put’
i used post() method instead of put bt it gives error
error: no matching function for call to ‘QHttp::post(QFile*&, QString&)’
1) i am nt getting what method should i use for uploading the file??
2)am using vsftpd server. can u tel me where is the uploaded data stored on this server????
3)is it necessary to use seperate http server for this??
plz reply urgently.

below is the code for http uploading files:

------------http_put.cpp---------------



#include "http.h"
#include <QFileDialog>
#include <QMessageBox>
#include <QProgressDialog>
#include <iostream>
#include <QDebug>
using namespace std;

http::http(QWidget *parent)
: QMainWindow(parent)
{
}

http::~http()
{

}

HttpGet::HttpGet(QObject *parent)
: QObject(parent)
{
connect(&http, SIGNAL(done(bool)), this, SLOT(HttpDone(bool)));
}

void HttpGet::putFile()
{
QString filename;
QString files = QFileDialog::getOpenFileName(0, tr("Select File"),"/home/supriya/supri.c");
if (files.isEmpty())
return;
QFile *file = new QFile(filename);
Q_ASSERT(file != NULL);
if(!file->open(QIODevice::ReadWrite))
{
qDebug() << "opern err" << file->fileName();
return;
}
qDebug() << "Upload start";
http.put(file,filename);
qDebug() << "Upload end";
}


------------this is header file------------


#ifndef HTTP_H
#define HTTP_H

#include <QtGui/QMainWindow>
#include <QUrl>
#include <QHttp>
#include <QFile>
#include <iostream>
#include <QFileInfo>

using namespace std;
class http : public QMainWindow
{
Q_OBJECT

public:
http(QWidget *parent = 0);
~http();
};

class HttpGet : public QObject
{
Q_OBJECT

public:
HttpGet(QObject *parent = 0);
bool getFile(const QUrl &url);
void putFile();
signals:
void done();

private slots:
void HttpDone(bool error);


private:
QHttp http;
QFile file;
};

#endif // HTTP_H

mcosta
25th February 2011, 23:56
I think you're little bit confused



1) i am nt getting what method should i use for uploading the file??


You are speaking about upload a file on vsftpd server, then you have to use FTP protocol.
See QFtp class. It has the QFtp::put method that allows to send file to a FTP server.



2)am using vsftpd server. can u tel me where is the uploaded data stored on this server????


it depends from vsftpd server configuration.

ChrisW67
26th February 2011, 00:11
The errors after running program are.

1)error: no matching function for call to ‘QFileDialog::getOpenFileName(HttpGet* const, QString, const char [5])’
2)14: error: no match for ‘operator=’ in ‘((HttpGet*)this)->HttpGet::file = (operator new(8u), (<statement>, ((QFile*)<anonymous>)))’
3)16: error: no match for ‘operator!=’ in ‘((HttpGet*)this)->HttpGet::file != 0’

These are compilation errors, and nothing to do with running your program. When faced with these sorts of errors you should:

Start at the first error message
Read the error message
Read the error message again. Really. The compiler is telling you something useful even if you can't see it the first time.
Read the documentation for the classes and methods you are trying to use
Have an Aha! moment and fix the problem
Move on to any remaining errors after trying to compile again


Only when it compiles will you be able to address the errors in the logic of your running program.