#ifndef CHECK_H#define CHECK_H#include <QMainWindow>#include <QDebug>#include <QMessageBox>#include <QtNetwork/QNetworkAccessManager>#include <QUrl>#include <QtNetwork/QNetworkRequest>#include <QtNetwork/QNetworkReply>#include <QThread>class Check : public QThread{public: Check(QObject *parent = 0) : QThread(parent) {} virtual void run();private slots: void end(QNetworkReply*);private: QNetworkAccessManager *Mgr;};#endif // CHECK_H
#include "check.h"Check::run(){ qDebug()<<"runn"; QNetworkAccessManager *Mgr = new QNetworkAccessManager(this); connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(end(QNetworkReply*))); manager->get(QNetworkRequest(QUrl("http://site.com")));}Check::end(QNetworkReply* reply){ qDebug()<<reply->readAll();}
D:\QT\Tools\QtCreator\bin\myprog\check.cpp:3: ошибка: ISO C++ forbids declaration of 'run' with no type [-fpermissive] Check::run() D:\QT\Tools\QtCreator\bin\myprog\check.cpp:3: ошибка: prototype for 'int Check::run()' does not match any in class 'Check' Check::run() ^D:\QT\Tools\QtCreator\bin\myprog\check.cpp:1: In file included from ..\myprog\check.cpp:1:0:D:\QT\Tools\QtCreator\bin\myprog\check.h:16: ошибка: candidate is: virtual void Check::run() virtual void run(); ^D:\QT\Tools\QtCreator\bin\myprog\check.cpp:11: ошибка: ISO C++ forbids declaration of 'end' with no type [-fpermissive] Check::end(QNetworkReply* reply) ^D:\QT\Tools\QtCreator\bin\myprog\check.cpp:11: ошибка: prototype for 'int Check::end(QNetworkReply*)' does not match any in class 'Check' Check::end(QNetworkReply* reply) ^D:\QT\Tools\QtCreator\bin\myprog\check.cpp:1: In file included from ..\myprog\check.cpp:1:0:D:\QT\Tools\QtCreator\bin\myprog\check.h:19: ошибка: candidate is: void Check::end(QNetworkReply*) void end(QNetworkReply*); ^
Check asd; asd.start();
QThread: Destroyed while thread is still runningQMutex: destroying locked mutexПрограмма неожиданно завершилась.
void Check::run(){ qDebug()<<"runn"; QNetworkAccessManager *Mgr = new QNetworkAccessManager(this); connect(Mgr, SIGNAL(finished(QNetworkReply*)), this, SLOT(end(QNetworkReply*))); Mgr->get(QNetworkRequest(QUrl("http://wapos.ru"))); exec();}void Check::end(QNetworkReply* reply){ qDebug()<<reply->readAll(); quit();}
QObject: Cannot create children for a parent that is in a different thread.(Parent is QThread(0x22fe40), parent's thread is QThread(0x12bdcc0), current thread is QThread(0x22fe40)QObject::connect: No such slot QThread::end(QNetworkReply*)QThread: Destroyed while thread is still running
asd.start();
QNetworkAccessManager *Mgr = new QNetworkAccessManager();Mgr->moveToThread(this);
C++ (Qt)void Check::run(){ qDebug()<<"runn"; QNetworkAccessManager Mgr; connect( &Mgr, SIGNAL(finished(QNetworkReply*)), this, SLOT(end(QNetworkReply*))); Mgr.get(QNetworkRequest(QUrl("http://wapos.ru"))); exec();}