QObject: Cannot create children for a parent that is in a different thread. - Wątki
Ostatnio zmodyfikowano 2013-06-23 14:47
look997 Temat założony przez niniejszego użytkownika |
QObject: Cannot create children for a parent that is in a different thread. - Wątki » 2013-06-23 13:27:33 Teraz pojawił się problem z samymi wątkami: QObject: Cannot create children for a parent that is in a different thread. (Parent is QThread(0x28fd88), parent's thread is QThread(0x129209c0), current thread is QThread(0x28fd88)
Jak to naprawić? class Producent : public QThread { public: Producent( int, int, Ui::OknaKlasa * ui ); void run(); public slots: void replyFinished( QNetworkReply * ); private: int n; int i; Ui::OknaKlasa * ui; };
Producent::Producent( int, int, Ui::OknaKlasa * ui ) { this->n = n; this->i = i; this->ui = ui; }
void Producent::run() { int ch2 = 1; QString sstring = "fd"; QNetworkAccessManager * manager = new QNetworkAccessManager( this ); connect( manager, SIGNAL( finished( QNetworkReply * ) ), this, SLOT( replyFinished( QNetworkReply * ) ) ); while( true ) { qDebug() << ch2++; manager->get( QNetworkRequest( QUrl( "https://adr.es/data.json" ) ) ); this->msleep( 2000 ); } }
void Producent::replyFinished( QNetworkReply * reply ) { qDebug() << "DONE"; QJsonDocument document = QJsonDocument::fromJson( reply->readAll() ); QString string; }
OknaKlasa::OknaKlasa( QWidget * parent ) : QMainWindow( parent ) , ui( new Ui::OknaKlasa ) { ui->setupUi( this ); Producent producent1( 123, 1, ui ); producent1.start(); }
|
|
Monika90 |
» 2013-06-23 14:47:22 QNetworkAccessManager * manager = new QNetworkAccessManager( this );
Tworzysz obiekt w nowym wątku, a this to wskaźnik do obiektu utworzonego w innym wątku i stąd problem. |
|
« 1 » |