Unsolved what is the best way to update UI by data(got from the non-mainThread)?
-
@J.Hilk thank you.
but as signal and slot are not in the same thread. is there any other way except these 2 method?- pass Struct as value;
- SetData() {mutex; m_data = data;} @the signal thread
GetData() {mutex; return m_data;} @the slot thread
-
@opengpu How big is your struct and how often do you emit the signal?
-
@jsulm ```
class Data
{
public:
VARIANT data1;
VARIANT data11;
VARIANT data111;
VARIANT data1111;
LONG errorCode;
public:
Data();
~Data();
};maybe emit every second, or even more frequently
-
is this a good way to emit signal in the non-thread non-qt Callback function?
WINAPI Callback(const Data& data) {//here is not mainThread; so i have to pass the data by value to the slot which is in mainThread; or i use mutex & save data to m_data, and then in slot mainThread getData also with mutex protect thread-safety g_qtObj->emit mySignal(); } class QtObj : public QObject { Q_OBJECT signals: void mySignal(); } QtObj g_obj; QtObj* g_qtObj = &g_obj;
-
@opengpu And how big is VARIANT?
1HZ isn't something I would care. In such a case I would exchange the data via signals/slots between the threads instead of messing up with threads synchronisation. -
-
-
@J.Hilk windows10 & x64
-
ok, so i will pass it by-value in connect & across theads
-
my exe recieve data from internet then update and show the data realtime, such as stock market realtime price changing very fast.