본문 바로가기
놀기/Qt

warning: '_sleep' is deprecated

by Hi~ 2022. 8. 1.

 

Qt에서 sleep() 함수를 사용하면 아래와 같이 에러가 난다.

warning: '_sleep' is deprecated: This function or variable has been superceded by newer library or operating system functionality. Consider using Sleep instead. See online help for details.

sleep() 함수를 억지로 쓸 방법은 있겠지만, 쓰지 말라고 하면 다 이유가 있지 않을까?

암튼....

 

QThread를 include 한 후에 아래와 같이 sleep(), msleep(), usleep()를 사용한다.

https://doc.qt.io/qt-6/qthread.html#static-public-members

 

QThread Class | Qt Core 6.3.2

 

doc.qt.io

QThread::msleep(1000);

 

아니면 c++에서 제공하는 sleep() 함수를 사용한다.

https://en.cppreference.com/w/cpp/thread/sleep_for

 

std::this_thread::sleep_for - cppreference.com

template< class Rep, class Period > void sleep_for( const std::chrono::duration & sleep_duration ); (since C++11) Blocks the execution of the current thread for at least the specified sleep_duration. This function may block for longer than sleep_duration d

en.cppreference.com

#include <thread>
#include <chrono>

{
    std::this_thread::sleep_for(std::chrono::milliseconds(1000));
)

댓글