c++ - Qt Threads call Function -


i have class 'a' , in class there method 'method1()' , method1 run in qthread. in method1 i'd call function in mainwindow class this: 'mainwindow window; window.func()'

when error message: qobject::setparent: cannot set parent, new parent in different thread

here code:

void gcode_int::parse_file(char* gcode_file, int file_length,mainwindow *window) {     window->fahre_on_pos(null,atoi(x_pos.c_str()),atoi(y_pos.c_str())); } 

here function in mainwindow:

void mainwindow::fahre_on_pos(char* g_command ,int x_pos, int y_pos) {     double y_schritte; double x_schritte;  int j =  1; int x_length = x_pos-x_pos_old; int y_length = y_pos-y_pos_old;  digitalwrite(x_treiber,1); digitalwrite(y_treiber,1);  if(x_length > 0) {     digitalwrite(x_richtung, 1); } if(x_length <= 0) {     digitalwrite(x_richtung,0);     x_length *= -1; }  if(y_length > 0) {     digitalwrite(y_richtung, 0); } if(y_length < 0) {     digitalwrite(y_richtung,1);     y_length *= -1; } y_schritte = round((y_length/1.25)*48);  if(y_schritte == 0) {     y_schritte =1;     digitalwrite(y_treiber,0); } if(x_schritte == 0)     digitalwrite(x_treiber,0);  x_schritte = round(((x_length/1.25)*200)/y_schritte); while(j <= y_schritte) {     for(int i=1;i<= x_schritte;i++)     {         digitalwrite(x_v, 1);         delay(1);         digitalwrite(x_v, 0);         delay(1);     }     if(x_schritte == 0)     {         digitalwrite(y_v, 1);         delay(4);         digitalwrite(y_v, 0);         delay(4);     }     else     {         digitalwrite(y_v, 1);         delay(1);         digitalwrite(y_v, 0);         delay(1);     }     j++; } x_pos_old = x_pos; y_pos_old = y_pos;  } 

hope can me

create slot in mainwindow receive parameters thread signal , invoke method

qt - updating main window second thread


Comments