문제

Qt를 사용하여 간단한 작업 플래너와 알림을 작성하고 있습니다. Qt는 주어진 작업의 날짜 및 시간이 현재 날짜 및 시간과 일치 할 때 사운드 파일을 재생합니다.

이를 구현하기 위해 목록에서 작업을 확인하여 현재 시간과 일치하는 항목이 있는지 확인하고 일치하는 경우 사운드 파일을 재생하는 QThread를 실행하고 있습니다.

이 ID 내 원래 수업 : 라코 디스

이것은 내 스레드 클래스입니다 : 라코 디스

내 구현 : 라코 디스

문제는 스레드가 완벽하게 실행되고 있지만 if() 루프 내부의 foreach() 조건은 어떤 이유로 든 충족되지 않는다는 것입니다.qDebugs를 사용하여 개별 날짜 / 시간 / 알람 설정 (t.ala)도 확인했습니다 (보시다시피).그들은 모두 괜찮습니다.

도움이 되었습니까?

해결책

Your if statement requires that the date and time match exactly, down to the millisecond. It is unlikely that your loop will evaluate at this exact moment. If you want to maintain similar logic (processing tasks in a loop), you might try sorting them by "next task first" (or perhaps using a queue), then testing in your if statement if the current QDateTime is equal-to-or-greater than the task date/time of the first task.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top