Идентификатор потока в QT

Вы также можете использовать SuppressMessageAttribute с ReSharper в качестве категории и All в качестве checkId на метод или класс, как показано ниже. Это более детально, чем отключение всего в файле, если вам нужен детальный контроль.

Протестировано с Visual Studio 2015 Update 3 и ReSharper Ultimate 10.0.2

[SuppressMessage("ReSharper", "All")]
private void MethodWithMultipleIssues()
{
    TestClass instance = null;
    // You would get an "Expression is always true" message
    if (instance == null)
    {
        Debug.WriteLine("Handle null");
    }
    else
    {
        // You would get an "Code is unreachable" message
        Debug.WriteLine("Handle instance");
    }
}

19
задан Termininja 17 December 2016 в 11:08
поделиться

3 ответа

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

19
ответ дан 30 November 2019 в 05:04
поделиться

В Windows приложения обычно «отсоединяются» от командной строки, когда вы их запускаете. Если вы добавите

win32:CONFIG+=console

, ваши приложения заблокируют командную строку и напечатают инструкции qDebug.

0
ответ дан 30 November 2019 в 05:04
поделиться

Поскольку базовая реализация QThread - это pthreads, вы можете использовать (я предполагаю, что вам нужен полезный идентификатор)

pthread_t = pthread_self();

изнутри выполняемого потока.

Значение, возвращаемое QThread :: currentThreadId (), равно не переносится.

-3
ответ дан 30 November 2019 в 05:04
поделиться
Другие вопросы по тегам:

Похожие вопросы: