How can I use functions from a class in a thread?
-
Hello, I am working on a project which I need to use the functions and variables of a class in a thread. The RadarGUI class is a widget that is created in the main.cpp, and the thread is a Qthread that is created as a class. I try to add the header of the RadarGUI widget in the thread, but does not let me use the functions, anyone know how I can solve this?
I cant use static functions because the functions needs to use the variables of the class.int main(int argc, char *argv[]) { QApplication a(argc, argv); RadarGUI w; //I need to use the functions and variables of w; w.show(); return a.exec(); }
header of RadarGUI:
class RadarGUI : public QMainWindow { Q_OBJECT public: RadarGUI(QWidget *parent = nullptr); ~RadarGUI(); void radarwidget(); void plotearM(ADC); void plotear_punto(int,int,int); private: Ui::RadarGUI *ui; QChartView *chartView; QPolarChart *grafPol = new QPolarChart(); QValueAxis *angularAxis = new QValueAxis(); QValueAxis *radialAxis = new QValueAxis(); hilo_cargarMatrizMain hilo1; hilo_plotMain hilo2; };
header of thread:
class hilo_plotWorker: public QThread { public: hilo_plotWorker(); void run(); };
-
@Uriel-Machado
Hello and welcome.Before you go any further: since it is a Qt rule you must not access any UI stuff in a secondary thread --- quite apart from the need for mutexes --- what do you think you are going to access in
RadarGUI
from a thread anyway?Threads can send signals to advise the UI thread of something happening and the UI thread can perform the UI action for them.