ftp upload fails



  • On Qt 5.7.0 win10 UWP winrt x86 version I get the messages below when trying to upload a file on my ftp server:

    qt.winrtrunner.app: Could not obtain NoDelay information from socket control
    qt.winrtrunner.app: Uploaded 126 of 126

    The result is the creation of an empty file with 0 bytes, the finished slot never fires.
    It helps when I copy
    data->deleteLater();
    reply->deleteLater();
    to the uploadProgress slot, 1 in 2 attempts succeed then with the creation of a 126 bytes file.

    But this is not good enough of course, anyone any idea why the finished Signal never fires ?

    class Uploader: public QObject
    {
        Q_OBJECT
    public:
        Uploader(QObject *p = 0): QObject(p)     {  }
    
        void start(const QString &file)     {
            QUrl url("ftp://ftp.xxxxxx.com/test.txt");
            url.setUserName("ftp_xxxx@yyyyy.com");
            url.setPassword("xxxxxx");
            url.setPort(21);
    
            data = new QFile(file, this);
            if (data->open(QIODevice::ReadOnly)) {
                reply = nam.put(QNetworkRequest(url), data);
                connect(reply, SIGNAL(uploadProgress(qint64, qint64)), SLOT(uploadProgress(qint64, qint64)));
                connect(reply, SIGNAL(finished()), SLOT(uploadDone()));
            }
            else
                qDebug() << "Oops";
        }
    
    public slots:
        void uploadProgress(qint64 bytesSent, qint64 bytesTotal)    {
            qDebug() << "Uploaded" << bytesSent << "of" << bytesTotal;
        }
    
        void uploadDone()     {
            qDebug() << "Finished" << reply->error();
            data->deleteLater();
            reply->deleteLater();
        }
    
    private:
        QNetworkAccessManager nam;
        QFile *data;
        QNetworkReply *reply;
    };
    


  • 2 things:

    • can you show us the snippet where you call start?
    • can you connect QNetworkReply::error signal to a slot to debug what is happening?

    one minor thing is make the two slots private as calling uploadDone() before calling start will operate on a dangling data pointer



  • I'm using the widgets/mainwindows/application example.

    I've tried the Error signal + slot, but it didn't execute (like the finished slot).

    In mainwindow.h I added the uploader object and in class MainWindow:

    private:
        QString filenameup;
        QFile fileup;
        Uploader u3;
    

    In mainwindow.cpp I added in bool MainWindow::save() :
    (pressing the Save button of the app's menu starts the upload)

        str1 = str1.left(126);
    
        QByteArray qbarr;
        qbarr.clear();
        qbarr.append(str1);
    
        QString path = QStandardPaths::standardLocations(QStandardPaths::AppDataLocation).value(0);
        filenameup = path + "\\test.txt";
        fileup.close();
        fileup.setFileName(filenameup);
        fileup.open(QIODevice::ReadWrite);
        fileup.write(qbarr);
        fileup.close();
    
        u3.start(filenameup);
    
        QTime t; 
        t.start();
        while(t.elapsed() < 3000) {
           QCoreApplication::processEvents(QEventLoop::AllEvents, 3000-t.elapsed());
        }
    
        fileup.close();
    
        return 0;
    }
    


  • Today I compiled this piece of coding with Qt 5.3 for Windows on a Windows 10 machine.
    And it runs like a charm, it executes the Finished slot and does the ftp upload.

    So it looks like it has sth to do with Qt 5.7 and winrt/uwp

    Note: Qt 5.3 doesn't know QStandardPaths::standardLocations(QStandardPaths::AppDataLocation).value(0);
    changed this to:
    filenameup = "test.txt";


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.