Je suis novice en QT et je fais de l'apprentissage.QT + Comment appeler un emplacement à partir d'un code C++ personnalisé s'exécutant dans un thread différent
Je voudrais déclencher un emplacement qui modifie un widget GUI à partir d'un thread C++ (actuellement un Qthread).
Malheureusement j'ai un: Échec d'ASSERTION à: Q_ASSERT (qApp & & qApp-> thread() == QThread :: currentThread());
ici est un code:
(MAIN + classe Thread)
class mythread : public QThread
{
public:
mythread(mywindow* win){this->w = win;};
mywindow* w;
void run()
{
w->ui.textEdit->append("Hello"); //<--ASSERT FAIL
//I have also try to call a slots within mywindow which also fail.
};
};
int main(int argc, char *argv[])
{
QApplication* a = new QApplication(argc, argv);
mywindow* w = new mywindow();
w->show();
mythread* thr = new mythread(w);
thr->start();
return a->exec();
}
fenêtre:
class mywindow : public QMainWindow
{
Q_OBJECT
public:
mywindow (QWidget *parent = 0, Qt::WFlags flags = 0);
~mywindow();
Ui::mywindow ui;
private:
public slots:
void newLog(QString &log);
};
Je suis curieux de savoir comment mettre à jour la partie IUG par le code dans un fil différent.
Merci de nous aider
La classe mythread doit contenir la macro Q_OBJECT – CiscoIPPhone