Ich bin neu in QT und lerne etwas.QT + Wie man Slot aus benutzerdefiniertem C++ - Code aufruft, der in einem anderen Thread läuft
Ich möchte einen Steckplatz auslösen, die ein GUI-Widget aus einem C++ - Thread (derzeit ein Qthread) ändern.
Unfortunatly ich a: Assertionsfehler bei: Q_ASSERT (qApp & & qApp-> Gewinde() == QThread :: current());
hier ist ein Code:
(Klasse Thread MAIN +)
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();
}
Fenster:
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);
};
So bin ich gespannt, wie in einem der gui Teil von Code zu aktualisieren anderer Thread.
Vielen Dank für
Die mythread-Klasse muss das Q_OBJECT-Makro enthalten – CiscoIPPhone