c++ - Program crashes when changing status bar text from thread -


i'm using qt interface , winapi threading , index files on hard drives. have status bar qlabel show directory indexing. change qlabel text pass pointer parameter function runs in thread. program crashes when changes qlabel text, if run without changing qlabel text executes propely. debugger stops @ last row of following

     function: ntdll!rtlpsetuserpreferreduilanguages 0x77d656a9  <+0x38ae>         add    (%eax),%al 0x77d656ab  <+0x38b0>         je     0x77d656c4 <ntdll!rtlpsetuserpreferreduilanguages+14537> 0x77d656ad  <+0x38b2>         mov    0x8(%ebp),%eax 0x77d656b0  <+0x38b5>         movb   $0x1,0x77d7f0a5 0x77d656b7  <+0x38bc>         mov    %eax,0x77d7f0a0 0x77d656bc  <+0x38c1>         int3 0x77d656bd  <+0x38c2>         movb   $0x0,0x77d7f0a5 

the function runs in thread

uintptr_t __stdcall threadfunction(void* labelptr) {      for(std::list<std::wstring>::iterator = discletters.begin(); != discletters.end(); ++i)     {         findallfilesindirectory((*i).c_str(), filesdata, (qlabel*)labelptr);     }     serializer<std::list<fileinfo>> xmlfile("d:\\res.xml");     xmlfile.serialize(filesdata); } 

and thread creation

threadhandle = _beginthreadex(null, 0, &threadfunction, (void*)(ui->currentdirectorylabel), null, null); 

i'm forced use winapi threading. can help?

to change qlabel text pass pointer parameter function runs in thread.

this problem. may not directly manipulate qwidgets thread other main thread (the thread called qapplication::exec()).

per qt documentation:

the gui classes, notably qwidget , subclasses, not reentrant. can used main thread.

the ideal solution re-work program worker threads qthreads , use qt's signals-and-slots mechanism handle inter-thread communication , synchronization automatically.

if cannot use qthreads, have set own inter-thread communication. 1 way shared queue protected mutex. worker thread(s) push items it, , gui thread poll occasionally.


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -