Discussion Board

Results 1 to 3 of 3

Hybrid View

  1. #1
    Registered User schroffi's Avatar
    Join Date
    Jan 2011
    Posts
    40
    Hello,
    i have a qt application where i have to download some files and pictures in the background while the appliction is going on. and the user should be informed when the upload is finished.

    My idea is to open a new thread and in a loop start the http requests (witch is done by a own class - using the QHTTP). But the thread is not waiting, and the requests are not starting. How can i do this?

    I subclass the qthread and use my class in the mainwindow

    Code:
    KurierDLThread* threadDl;
    threadDl = new  KurierDLThread(this);
        if(threadDl->isRunning()) return;
    
        qDebug() << "start thread";
        threadDl->setValues(boolNach,boolGall,boolVideo,boolHoro,boolTv,strStorageDataPath);
    
        connect(threadDl,SIGNAL(signalAddLoading()),this, SLOT(slotAddLoadingDL()));
        connect(threadDl,SIGNAL(signalRemoveLoading()), this,SLOT(slotRemoveLoadingDL()));
    
        threadDl->start();

    And here the SUbclass:
    part of .h


    Code:
    class KurierDLThread : public QThread
    {
        Q_OBJECT
    public:
        KurierDLThread(QObject* parent = 0);
        void setValues(bool boolSNachrichten, bool boolSGallery, bool boolSVideo, bool boolSHoroskop, bool boolSTv,QString strPath);
        void saveAll();
    protected:
        void run();
    }
    part of .cpp

    Code:
    void KurierDLThread::run()
    {
        emit signalAddLoading();
        QObject qWaitObj(this->parent());
        qWaitAll = new QObject(this->parent());
        int intRes = kurDatabaseObj->deleteFolders(0,strStorageDataPath);
         if(boolStatusNachrichten)
         {
             saveNachrichten();
         }
         if(boolStatusTv)
         {
             saveTv();
         }
         if(boolStatusGallery)
         {
             qDebug() << "save gallerys";
             saveGallery();
         }
         if(boolStatusVideo)
         {
             qDebug() << "save video";
             saveVideo();
         }
    
         if(boolStatusHoroskop)
         {
             saveHoroskop(&qWaitObj);
         }
         emit signalRemoveLoading();
         deleteLater();
    }

    Code:
    void KurierDLThread::saveHoroskop(QObject* qWaitObj)
    {
        QSqlTableModel model;
    
        QString strFilter = "feedtype='";
        strFilter += "horoskop";
        strFilter += "'";
        qDebug() << "READ" << strFilter;
        model.setTable("feed_config");
        model.setFilter(strFilter);
        model.select();
    
        if( model.rowCount()> 0)
         {
             qDebug() << "horoskop read";
    
             QSqlRecord record = model.record(0);
    
    
             QString  strFilename = strStorageDataPath + "/horoskop.xml";
              qDebug() << "config file : " << strFilename;
              IqNetworkDataObject* iqDownloadObj = new IqNetworkDataObject(this->parent());
              qDebug() << "nw thread" << iqDownloadObj->thread();
             // iqDownloadObj->moveToThread(this->thread());
              qDebug() << "nw thread2 " << iqDownloadObj->thread();
              qDebug() << "this thread " << this->thread();
              connect(iqDownloadObj,SIGNAL(signalAddLoading()), this, SLOT(slotAddLoading()));
              connect(iqDownloadObj,SIGNAL(signalRemoveLoading()), this, SLOT(slotRemoveLoading()));
              iqDownloadObj->requestFile(record.value("feedurl").toString(),strFilename);
              iqDownloadObj->deleteLater();
    
    
         }
    
    }
    THX paul
    Last edited by schroffi; 2011-06-09 at 10:30.

  2. #2
    Registered User lucarocchi's Avatar
    Join Date
    May 2009
    Location
    Rome
    Posts
    253
    QHttp deprecated ... you should consider rewrite that code by using QNetwork api
    Keep it simple, stupid (I think to myself)
    borg - http://store.ovi.com/content/116105

  3. #3
    Nokia Developer Moderator divanov's Avatar
    Join Date
    Oct 2009
    Posts
    4,326
    Yes, QHttp is deprecated and QNetworkAccessManager is good enough to do it within one thread.

Similar Threads

  1. Replies: 6
    Last Post: 2011-01-20, 09:44
  2. Replies: 3
    Last Post: 2010-08-25, 07:20
  3. How to upload file with QHttp?
    By wshiyc in forum Qt
    Replies: 2
    Last Post: 2010-07-22, 10:55
  4. Replies: 19
    Last Post: 2010-03-29, 08:09

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved