Witam, potrzebuję zrobić taki timer któremu podaje czas np. 10s, i w QLabel jest odliczanie, gdy dojdzie do "0" coś się dzieję, nie mam pojęcia jak się za to zabrać, musi to być pthreads.
Pozdrawiam
Własny timer w oparciu o QT i PThreads
- Rejestracja: dni
- Ostatnio: dni
- Postów: 45
- Rejestracja: dni
- Ostatnio: dni
- Postów: 2412
Kiepsko opisales swoj problem. Na ta chwile moge jedynie powiedziec, zebys zrobil jakas zmienna, do ktorej dostep bedzie mozliwy z obu watkow. Kiedy czas w labelu dojdzie do zera, ustawiasz ta zmienna. Drugi watek caly czas czeka na jej ustawienie, zczytuje i wykonuje jakas akcje. Poczytaj o pthread_cond_* albo opisz problem w wiekszych szczegolach.
- Rejestracja: dni
- Ostatnio: dni
- Postów: 45
Właśnie o to mi chodzi tylko pojęcia nie mam jak to połączyć składniowo, UI -> QT, wątki z pThreads. W skrócie licznik leci od 10 do 0, po czym nastepuję np. wyśiwetlenie QDialog.
- Rejestracja: dni
- Ostatnio: dni
- Postów: 45
Po przerwie odpisuje, dlaczego po utworzeniu wątku pThreads np. gdy wywołuję poniższą funkcję, gui wraz z programem wyłacza się ?
Czy da się to posklejać ? tzn. pThreads + GUI ?
void* watek(void* _arg) {
MainWindow w;
w.okienkoKoncowe();
cout<<("Witaj w równoległym świecie!");
return NULL;
}
void MainWindow::on_newGameButton_clicked()
{
punkty = 0;
tablicaWylosowanych.clear();
ui->confirmButton->setEnabled(true);
ui->endGameButton->setEnabled(true);
ui->nextButton->setEnabled(true);
noweDzialanie();
int N=5;
pthread_t id [N];
pthread_create(&id[1],NULL,watek,NULL);
}
Błędy:
QApplication: Object event filter cannot be in a different thread.
QApplication: Object event filter cannot be in a different thread.QObject::setParent: Cannot set parent, new parent is in a different thread
QApplication: Object event filter cannot be in a different thread.
QApplication: Object event filter cannot be in a different thread.
QApplication: Object event filter cannot be in a different thread.
QApplication: Object event filter cannot be in a different thread.
QApplication: Object event filter cannot be in a different thread.
QApplication: Object event filter cannot be in a different thread.
QApplication: Object event filter cannot be in a different thread.
QApplication: Object event filter cannot be in a different thread.
QApplication: Object event filter cannot be in a different thread.
QApplication: Object event filter cannot be in a different thread.
QApplication: Object event filter cannot be in a different thread.
QApplication: Object event filter cannot be in a different thread.
QApplication: Object event filter cannot be in a different thread.
POZDRAWIAM !