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
part of .cppCode: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(); }
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(); }
THX paulCode: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(); } }

Reply With Quote

