QThread Problem
Verfasst: 6. Mai 2007 02:19
Hi,
ich habe hier ein Problem wo ich einfach nicht weiter komme
Ich möchte in der Methode run den Text für connections setzen, was jedoch nicht gehen will. Als Fehler bekomme ich
Wie könnte man das lösen ?
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;
};
QObject: Cannot create children for a parent that is in a different thread.
Wie könnte man das lösen ?