Download image



  • I am not able understand the example given on enginio website to download images stored on enginio

    It would be helpful if someone can help me with it


  • Lifetime Qt Champion

    Hi,

    You should add a link to the example you are referring to



  • "You will be able to go through links here":https://engin.io/documentation/qt/qtenginiocpp/enginio-qt-image-gallery-cpp-example.html

    now see i am able to get how it is uploading
    but i am not able to get how is it downloading

    it will show you all the files in case you need to find something from another file
    sorry for so many files


  • Lifetime Qt Champion

    By download, do you mean showing the images in the list view ? From a quick look at the doc, the heavy lifting is done in the EnginioModel



  • well i am basically not able to get the query that is being done to get the image
    plus im interested in storing the image in QImage object so that i can show it later



  • The whole magic is written in 3 functions:
    @
    void ImageObject::setObject(const QJsonObject &object)
    void ImageObject::replyFinished(EnginioReply *enginioReply)
    void ImageObject::downloadFinished()
    @

    The first one is checking if the image is not a local file, if it is not then it asks for download url (aka "expiringUrl'). The 2nd function extract the url and asks for the file. The last function constructs the image from the received byte array.



  • This is what i am doing right now
    @
    QJsonObject query;

     query.insert("objectType", QString("objects.image"));
     EnginioReply *reply=client->query(query);
    
     connect(reply,SIGNAL(finished(EnginioReply*)),this,SLOT(showResult(EnginioReply*)));
    
     connect(client,SIGNAL(error(EnginioReply*)),this,SLOT(showError(EnginioReply*)));
    

    void MainWindow::showResult(EnginioReply *reply)
    {
    qDebug()<<"Inside Result";
    qDebug()<<reply->isFinished();

    QString url=reply->data().value("expiringUrl").toString();
    QNetworkRequest request(url);
    m_reply=client->networkManager()->get(request);
    m_reply->setParent(this);
    connect(m_reply,SIGNAL(finished()),this,SLOT(downloadFinished()));
    

    }
    void MainWindow::downloadFinished()
    {
    QByteArray imageData=m_reply->readAll();
    m_image.loadFromData(imageData);
    qDebug()<<m_image.isNull()<<" Check for NULL";
    pix=QPixmap::fromImage(m_image.scaled(100,100,Qt::KeepAspectRatio,Qt::SmoothTransformation));
    ui->label->setPixmap(pix);
    }

    @



  • You forgot to write which part doesn't work and what is the error message.



  • oh my apologies

    @
    pix=QPixmap::fromImage(m_image.scaled(100,100,Qt::KeepAspectRatio,Qt::SmoothTransformation));
    ui->label->setPixmap(pix);
    @

    no image is displayed
    the error message is "QImage::scaled: Image is a null image"

    this error comes in the same segment of code



  • Ok, have you tried to debug it? Are you sure that you are getting the right url? What kind of data the server returned? Check all replies for isError() value, try to printout all data() values.



  • no i am not getting any url
    it's empty



  • so what reply->data() returns?



  • @
    QJsonObject({"query": {"limit": 100,"query": {}},"results": [{"createdAt": "2014-01-13T14:26:41.254Z","file": {"id": "52d3f78a698b3c51a1028733","objectType": "files"},"id": "52d3f7a1698b3c623202389e","name": "file1","objectType": "objects.image","updatedAt": "2014-01-13T14:26:41.254Z"}]})
    @

    Is it possible that the problem that i am having is because i have installed qt 5.2 offline and QtEnginio 0.6.0?



  • You should use Enginio 1.0.1 in the first place, please update your installation.

    In your reply there is no url, because you haven't ask for it, use Enginio::Client::downloadUrl method to get it.


Log in to reply
 

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