EDIT:
I tried to do what you guys told me in the comments ...:
Citizen * c = new Citizen(this); QThread thread; c->moveToThread(&thread); connect(&thread, SIGNAL(started()), c, SLOT(ProcessActions())); thread.start();
This causes even more errors:
QThread: Destroyed while thread is still running ASSERT failure in QThread::setTerminationEnabled(): "Current thread was not started with QThread.", file c:\ndk_buildrepos\qt-desktop\src\corelib\thread\qthread_win.cpp, line 542 Invalid parameter passed to C runtime function. Invalid parameter passed to C runtime function. QObject::killTimers: timers cannot be stopped from another thread
I am having problems with this error ... Iโve been stuck with this for 2 days and cannot get a solution.
Title:
class Citizen : public QThread { Q_OBJECT QNetworkAccessManager * manager; private slots: void onReplyFinished(QNetworkReply* net_reply); public: Citizen(QObject * parent); void run(); };
Implementation:
Citizen::Citizen(QObject * parent) { manager = new QNetworkAccessManager; connect(_net_acc_mgr, SIGNAL(finished(QNetworkReply*)), this, SLOT(onReplyFinished(QNetworkReply*))); } void Citizen::onReplyFinished(QNetworkReply* net_reply) { emit onFinished(net_reply); } void Citizen::run() { manager->get(QNetworkRequest(QUrl("http://google.com")); QEventLoop eLoop; connect(manager, SIGNAL( finished( QNetworkReply * ) ), &eLoop, SLOT(quit())); eLoop.exec(QEventLoop::ExcludeUserInputEvents); qDebug() << "loaded google!"; exec(); }
When manager-> get () starts, the following error appears:
QObject: Cannot create children for a parent that is in a different thread. (Parent is QNetworkAccessManager(0xc996cf8), parent thread is QThread(0xaba48d8), current thread is Citizen(0xca7ae08)
When eLoop.exec () is executed:
QObject::startTimer: timers cannot be started from another thread
I start this thread as follows:
Citizen * c = new Citizen(this); c->start();
Why is this happening? How to solve this?