×

Discussion Board

Results 1 to 3 of 3

Threaded View

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    40

    Using QHttp with Qthread

    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.

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
  •  
×