| Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date | |
| All threads index page 4 | |
Hi!
I wrote class which should be able to download files using ftp and http
protocol. And it works almost fine. I can download files correctly, but when
I try to get not existing files it fails. I supposed to get error set to true
in commandFinised and requestFinished signals in such cases but I don't. What
I supposed to do to to handle such cases?
My program:
#ifndef __MAIN_H
#define __MAIN_H
#include <QObject>
#include <QScriptable>
#include <QStringList>
#include <QUrl>
#include <QFile>
#include <QEventLoop>
class WebGet :
public QObject
{
Q_OBJECT
private:
QEventLoop loop;
QString error;
QFile file;
bool downloadFtp(QUrl & url);
bool downloadHttp(QUrl & url);
public:
WebGet();
QString errorString(void);
bool download(QUrl & url, const QString & fileName);
private slots:
void httpRequestFinished(int id, bool err);
void ftpFinished(int id, bool err);
};
#endif /* __MAIN_H */
#include <QApplication>
#include <QStringList>
#include <QFile>
#include <QHttp>
#include <QFtp>
#include <QDir>
#include <QDebug>
#include "main.h"
#include "main.moc"
WebGet::WebGet()
{
}
bool WebGet::downloadFtp(QUrl & url)
{
QFtp ftp;
connect(&ftp, SIGNAL(commandFinished(int, bool)), this, SLOT(ftpFinished(int,
bool)));
ftp.connectToHost(url.host(), url.port(21));
if (1 == loop.exec())
return false;
if (url.userName().isEmpty())
ftp.login("anonymous", "test@xxxxxxxx");
else
ftp.login(url.userName(), url.password());
if (1 == loop.exec())
return false;
QString path = url.path();
QString dir = path.left(path.lastIndexOf("/"));
QString fileName = path.mid(path.lastIndexOf("/") + 1);
ftp.cd(QString("/%1").arg(dir));
if (1 == loop.exec())
return false;
file.open(QIODevice::WriteOnly);
ftp.get(fileName, &file);
if (1 == loop.exec()) {
file.close();
file.remove();
return false;
}
file.close();
return true;
}
bool WebGet::downloadHttp(QUrl & url)
{
QHttp http;
connect(&http, SIGNAL(requestFinished(int, bool)), this,
SLOT(httpRequestFinished(int, bool)));
http.setHost(url.host(), url.port(80));
if (1 == loop.exec())
return false;
if (!url.userName().isEmpty()) {
http.setUser(url.userName(), url.password());
if (1 == loop.exec())
return false;
}
file.open(QIODevice::WriteOnly);
http.get(url.path(), &file);
if (1 == loop.exec()) {
file.close();
file.remove();
return false;
}
file.close();
return true;
}
void WebGet::ftpFinished(int id, bool err)
{
QFtp *ftp = (QFtp*)sender();
if (err) {
error = ftp->errorString();
loop.exit(1);
}
loop.exit(0);
}
void WebGet::httpRequestFinished(int id, bool err)
{
QHttp *http = (QHttp*)sender();
if (err) {
error = http->errorString();
loop.exit(1);
}
loop.exit(0);
}
bool WebGet::download(QUrl & url, const QString & fileName)
{
file.setFileName(QString("%1/%2").arg(QDir::homePath()).arg(fileName));
// if no protocol specified we'll try http first than ftp
if (url.scheme() == "") {
url.setScheme("http");
if (downloadHttp(url))
return true;
else
url.setScheme("ftp");
}
if (url.scheme() == "ftp")
return downloadFtp(url);
if (url.scheme() == "http")
return downloadHttp(url);
error = QString("No valid protocol specified!");
return false;
}
QString WebGet::errorString(void)
{
return error;
}
int main (int argc, char *argv[])
{
QApplication app(argc, argv);
WebGet webget;
QUrl u1("http://www.pers.pl/notexists");
QUrl u2("ftp://ftp.pers.pl/notexists");
QString f1("out.http");
QString f2("out.ftp");
qDebug() << webget.download(u1, f1);
qDebug() << webget.download(u2, f2);
return 0;
}
Regards,
--
[ signature omitted ]
Attachment:
signature.asc
Description: This is a digitally signed message part.
Hi Everyone, Qt 4.3.1 compiled using MSVC Standard. I am porting an existing Windows application to Qt. The application uses a symbol font to draw musical notation. The windows version used a transformation matrix to apply zooming, and it worked well from 1% to 1000%. The Qt version applies the zooming to a painter in a QFrame paint event. It only seems to work up to 210%. Over 210% the symbol font characters are drawn at a much smaller size. For example: painter.setFont( QFont( "Times New Roman", 30, -1, false ); painter.scale( iZoom / 100.0, iZoom / 100.0 ); painter.drawText( 300, 300, "&" ); The above works well. I can change the iZoom up to 500% and the character draws correctly. If I change it to use "Opus" font, which is a symbol font, then it doesn't. It works OK up to 210%, then jumps to a smaller size at 220%. Windows can transform the font correctly, but Qt painter doesn't. Eventually, I hope to convert to use GraphicsView. But I do not want to spend all that time rewriting, if the font is not going to work anyway. Thanks in advance for any assisstance! -- [ signature omitted ]
Dnia niedziela, 23 września 2007, Rafał Cygnarowski napisał: > Hi! > > I wrote class which should be able to download files using ftp and http > protocol. And it works almost fine. I can download files correctly, but > when I try to get not existing files it fails. I supposed to get error set > to true in commandFinised and requestFinished signals in such cases but I > don't. What I supposed to do to to handle such cases? Noone knows what's wrong with this? Is it my code problem or it's Qt feature/bug? Regards, -- [ signature omitted ]
Attachment:
signature.asc
Description: This is a digitally signed message part.