Я пытаюсь передать структуру данных в поток QT, но безуспешно.
вот что я делаю и сделал.
Я готовлю данные для потока, как это, и затем попытался передать подготовленные данные в поток перед запуском.
void mytable::prepare_data(){
// get table row count
int rowCount = ui->my_table_view->rowCount();
// create structure array based on rowCount
pnp_com_info pnp_data[rowCount];
/* pnp_com_info structure defined it top of file below includes to make it global
struct pnp_com_info{
QString com_name = "";
int x = 0;
int y = 0;
int angle = 0;
bool status = false;
};
*/
// loop on table rows columns and load pnp_data with data of columns
// PROBLEM : how to pass pnp_data structure to thread side ?
// can pass basic vars like
RunJobThread->mynum = 10;
// start QT thread
RunJobThread->start();
// std:: thread experiment
// std::stdthreadtest(pnp_data,rowCount);
}
run_job_thread.h исходный код
#ifndef RUN_JOB_THREAD_H
#define RUN_JOB_THREAD_H
#include <QObject>
#include <QThread>
class run_job_thread : public QThread
{
Q_OBJECT
public:
run_job_thread();
void run();
int mynum;
struct pnp_com_info_thread{
QString com_name = "";
int x = 0;
int y = 0;
int angle = 0;
bool status = false;
};
bool Stop; // bool to stop the job
signals:
void select_row_of_table_signal(int);
public slots:
};
#endif // RUN_JOB_THREAD_H
run_job_thread. cpp исходный код
#include "run_job_thread.h"
#include <QtCore>
run_job_thread::run_job_thread()
{
}
// run the thread
void run_job_thread::run(){
qDebug() << "my num passed value is : "<<this->mynum; // output : 10
// Goal : loop on pnp_data structure and emit signal to table rows
emit select_row_of_table_signal(5);
}
вещи, которые я пробовал
вместо struct я попытался использовать другие контейнеры данных, такие как map, multimap, vector, но они дают ошибку, так как я инициализирую структуру pnp_com_info внутри функции mytable :: prepare_data () на основе rowCount, который делает ее локальной и ограниченный функцией prepare_data (), но с map, multimap, vector я планировал, что они будут глобальными, и я смогу получить к ним доступ из потока, однако это не сработало.
std::map<std::string, int,int,int> pnp_com_info; // error: too many template arguments for class template 'map'
std::multimap<std::string, int,int,int,bool> pnp_com_info; // error: too many template arguments for class template 'multimap'
std::vector<std::string, int,int,int,bool> pnp_com_info; // error: too many template arguments for class template 'vector'
я также попробовал std :: thread, который был частичным успехом, я имею в виду, что он работал нормально, но похоже, что std :: thread не работает с потоком QT GUI, как при запуске приложения GUI go freez, хотя std :: thread делал свою работу