Seite 1 von 1

QThread Problem

Verfasst: 6. Mai 2007 02:19
von tsluga
Hi,

ich habe hier ein Problem wo ich einfach nicht weiter komme

Code: Alles auswählen

class MyWindow : public QMainWindow, public QThread{
	
	public:
		MyWindow()
		:infoWidget(new QWidget()),connections(new QLabel()){
			initLayout();
			connections->setText("Empty");
			setCentralWidget(infoWidget);		
			QThread::start();
		}
	protected:
 		void run(void){
 			for(int i = 0; i < 100; i++){
				std::stringstream stream;
				stream<<"connections : "<<i;
				std::cout<<stream.str()<<std::endl;
				connections->setText(stream.str().c_str());
				
 			}
 		}
		void initLayout(void){
			BorderLayout *layout = new BorderLayout;
 			layout->addWidget(connections,BorderLayout::East);
			infoWidget->setLayout(layout);
		}
	private:
		QWidget *infoWidget;
		QLabel  *connections;
};
Ich möchte in der Methode run den Text für connections setzen, was jedoch nicht gehen will. Als Fehler bekomme ich
QObject: Cannot create children for a parent that is in a different thread.

Wie könnte man das lösen ?

Verfasst: 6. Mai 2007 13:05
von Christian81
QMainWindow und QThread? Was soll das denn? Zeichnen kann man nur im Hauptthread.