संपादित करें:QObject: एक माता पिता के एक अलग सूत्र में है कि के लिए बच्चों बनाया नहीं जा सकता
मैं कर क्या तुम लोग मुझे टिप्पणी में कहा था की कोशिश की ...:
Citizen * c = new Citizen(this);
QThread thread;
c->moveToThread(&thread);
connect(&thread, SIGNAL(started()), c, SLOT(ProcessActions()));
thread.start();
यह और भी पैदा करता है त्रुटियों:
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
मैं इस त्रुटि के साथ समस्या हो रही हूँ ... मैं पहले से ही 2 दिनों के लिए इस पर अटक कर रहा हूँ और एक समाधान नहीं मिल सकता है।
हैडर:
class Citizen : public QThread
{
Q_OBJECT
QNetworkAccessManager * manager;
private slots:
void onReplyFinished(QNetworkReply* net_reply);
public:
Citizen(QObject * parent);
void run();
};
कार्यान्वयन:
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();
}
जब प्रबंधक> get() निष्पादित हो जाता है, मैं निम्न त्रुटि:
QObject: Cannot create children for a parent that is in a different thread.
(Parent is QNetworkAccessManager(0xc996cf8), parent's thread is QThread(0xaba48d8), current thread is Citizen(0xca7ae08)
जब eLoop.exec() ई हो जाता है xecuted:
Citizen * c = new Citizen(this);
c->start();
इस क्यों होता है:
QObject::startTimer: timers cannot be started from another thread
मैं निम्नलिखित तरीके से इस सूत्र शुरू? इसे कैसे हल करें?
वहाँ इस विषय [धागे, घटनाक्रम और QObjects] के लिए एक अच्छा लेख (है http://qt-project.org/wiki/ Threads_Events_QObjects # 913fb94dd61f1a62fc809f8d842c3afa)। यदि आपका वर्ग नागरिक धागे में काम करता है तो आपको इसे QThread से प्राप्त नहीं करना चाहिए, क्योंकि QThread से विरासत का उद्देश्य धागे में कुछ काम नहीं करना है, लेकिन धागे का प्रबंधन करना है। –