ASSERT failure in QCoreApplication::sendEvent: "Cannot send events to objects owned by a different thread. Current thread 22fe34. Receiver '' (of type 'QProgressBar') was created in thread 5d70b8", file kernel\qcoreapplication.cpp, line 347
Invalid parameter passed to C runtime function.
Invalid parameter passed to C runtime function.
ASSERT failure in QCoreApplication::sendEvent: "Cannot send events to objects owned by a different thread. Current thread 22fe28. Receiver '' (of type 'QProgressBar') was created in thread 5d70b8", file kernel\qcoreapplication.cpp, line 347
Invalid parameter passed to C runtime function.
Invalid parameter passed to C runtime function.
вот пример кода
#include <QApplication>
#include <QLabel>
#include <QtGui>
#include "thread.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QProgressBar *bar1 = new QProgressBar;
QProgressBar *bar2 = new QProgressBar;
MyThread thread1(bar1);
MyThread thread2(bar2);
thread1.start(QThread::NormalPriority);
thread2.start(QThread::LowPriority);
bar1->show();
bar2->show();
return app.exec();
}
thread.h
#ifndef THREAD_H
#define THREAD_H
#include <qapplication.h>
#include <qthread.h>
#include <qprogressbar.h>
#include <qgridlayout.h>
#include <qlabel.h>
// ======================================================================
class MyThread : public QThread {
QProgressBar* m_pprb;
public:
MyThread(QProgressBar* pprb) : QThread()
, m_pprb(pprb)
{
}
void run()
{
for(int i = 0; i <= 100000000; ++i) {
m_pprb->setValue(i / 1000000);
}
}
};
#endif // THREAD_H
ну и про файл
SOURCES += main.cpp
CONFIG += qt warn_on release thread
TARGET = Threads
TEMPLATE = app
HEADERS += thread.h
окно выскакивает с такой ошибкой:
this applicatoin has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
правда в книге вот эта строка
m_pprb->setValue(i / 1000000);
выглядела так:
m_pprb->setProgress(i / 1000000);
но setProgress не существует, похоже она была чем то заменена))