c++ - QT Thread exchange data -


i have class inherits qthread, create several instances of class , makes program multi-thread.

i'm using slots/signals exchange data between threads , main thread (threads creator).

i had this:

void foundnewfile(qstring sourcedrive, qstring path, qstring filename); 

this working perfect.

now decided share metadata of files, this, have own large struct, did:

void foundnewfile(qstring sourcedrive, qstring path, qstring filename, metadata* meta); 

this metadata large, contains different data types , have several linked structs. when signals emitted, in main thread, when try do:

meta->datetime->creationhour; 

i access denied error.

1) doing (without metadata) right or 1 wrong?

2) what's solution?

p.s. tried q_declare_metatype , qregistermetatype together, didn't work.

never implement new slots if inherit qthread. not want. qthread object manages thread, not thread. your qthread-derived objects live in main thread, slots run in main thread (not new thread!)

the correct solution is:

  1. do not subclass qthread. instantiate qthread object.
  2. subclass qobject create worker.
  3. instantiate worker , move new thread, using qobject::movetothread().
  4. start qthread.
  5. now, when use signals , slots, slots run in correct thread.

see official qthread documentation example.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -