Suresh
Suresh

Reputation: 9605

Thread id in Qt

How to print the thread id using qDebug() on windows environment of Qt.

Upvotes: 26

Views: 29049

Answers (3)

syrius
syrius

Reputation: 21

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.

Upvotes: -4

Henrik Hartz
Henrik Hartz

Reputation: 3675

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.

Upvotes: -1

Idan K
Idan K

Reputation: 20901

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().

Upvotes: 30

Related Questions