QT + Comment appeler un emplacement à partir du code C ++ personnalisé exécuté dans un thread différent

Je suis nouveau sur QT et je fais un certain apprentissage.

Je voudrais déclencher une fente pour modifier une interface graphique widget à partir d'un C++ fil(Actuellement un Qthread).

Malheureusement je reçois un: ASSERTION failed: Q_ASSERT(qApp && qApp->thread() == QThread::currentThread());

voici un code:

(PRINCIPAL + 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);
};

Donc je suis curieux de savoir comment mettre à jour la partie interface utilisateur par le code dans un thread différent.

Merci pour votre aide

source d'informationauteur | 2009-07-17