Hello,
Could anyone tell me how to print the thread id using qDebug() on windows environment of QT.
-Suresh
Hello,
Could anyone tell me how to print the thread id using qDebug() on windows environment of QT.
-Suresh
I'm assuming you want the thread id of the currently executing thread (and not the thread id of a specific QThread object):
qDebug() << QThread::currentThreadId();
Things to consider: The method returns a platform specific id (check the docs). In windows you cannot use this id with Win32 API functions since it returns a pseudo id and not the real thread id.
If your application will only run in Windows and you need to do something meaningful with the thread id it would probably be best if you used GetCurrentThreadId().
On windows, applications normally "detatch" from the command line when you execute them. If you add
win32:CONFIG+=console
your applications will block the command prompt, and print the qDebug statements.
Since a QThread's underlying implementation is pthreads, you can use (I"m assuming you want a usable ID)
pthread_t = pthread_self();
from within the thread that is executing.
The value returned from QThread::currentThreadId() is not portable.