I can’t create a thread (c ++ 11) inside a class method - every time a compilation error:

C: \ Qt \ Qt5.8.0_mingw \ Tools \ mingw530_32 \ i686-w64-mingw32 \ include \ c ++ \ functional: 1505: error: no type named 'type' in 'class std :: result_of (Values_Refresher_Class *, QTableWidget *, Values_Refresher_Class *)> 'typedef typename result_of <_Callable (_Args ...)> :: type result_type;

C: \ Qt \ Qt5.8.0_mingw \ Tools \ mingw530_32 \ i686-w64-mingw32 \ include \ c ++ \ functional: 1526: error: no type named 'type' in 'class std :: result_of (Values_Refresher_Class *, QTableWidget *, Values_Refresher_Class *)> '_M_invoke (_Index_tuple <_Indices ...>)

Here is the code:

#include <thread> // Функция запуска потока void Values_Refresher_Class::Start(QTableWidget *Table) { // Установить флаг работы потока To_Work = true; // Задать потоку функцию thread Refresher_Thread = thread(&Values_Refresher_Class::Refresher_Handler, Table, this); } // Функция обработчика потока void Values_Refresher_Class::Refresher_Handler(QTableWidget *Table) { // Пока установлен флаг работы потока while(To_Work) { // Обновить список переменных Refresh_Values(Table); // Остановить поток на Refresh_Delay QThread::sleep(Refresher_Delay); } } 

Climbed a bunch of forums and I just can’t understand what's the matter - if you create a stream in main, then everything works, but if you transfer the stream to a class, then everything stops working immediately. What can be wrong?

I work in QT Creator under MinGW. I use not Qt-shny flows, but standard, since I want to learn how to work with them

  • Give the text of the message text, not a picture. Give the code Refresher_Handler . And since the arguments seem confused, this should go first. - VTT
  • @VTT Added as you requested - George Tuzikov

2 answers 2

this should be the first argument:

 ::std::thread Refresher_Thread{&Values_Refresher_Class::Refresher_Handler, this, Table}; 
  • Thanks, it helped. But can you explain how this works? - George Tuzikov
  • @GeorgeTuzikov I do not know what is there to explain. the constructor needs arguments in that order, that's all. - VTT

The Refresher_Handler method is not static, so it has one more hidden parameter: this is where the Refresher_Handler method will be called.

Either declare it static, or add an additional argument to the thrread constructor:

 thread(&Values_Refresher_Class::Refresher_Handler, this, Table, this); 
  • Did not help. I can't make it static, because non-static method is called in this method - George Tuzikov