c++ - QtGui5 not loaded -
i developing application in c++
, winapi
, qt
. application communicates through serial com ports. user can open multiple pairs of ports , opened port listens other port constantly. implement functionality use windows threads.there method named startread()
reads other port , changes text area.
void sendandreceive::startread(){ dword numread = 0; std::string hex; while (1) { char *buffer = (char *)malloc(sizeof(char) * 500); bool ret = readfile(porthandler, buffer, 500, &numread, 0); if (!ret) { std::string errormessage = ""; } buffer[numread] = '\0'; std::string receiveddata(buffer); qstring qdata(receiveddata.c_str()); if (ui->checkbox->ischecked()) { std::string receiveddata(buffer); hex= stringtohex(receiveddata); qstring qdata1(hex.c_str()); emit ashex(qdata1); } qstring qdata2(receiveddata.c_str()) ; emit finished(qdata2); free(buffer); } }
and there thread writes data periodically other port. example , if enter 2 seconds in text line , program writes data other port @ every 2 seconds , method writeperiodic()
.
void sendandreceive::writeperiodic(){ dword numwritten; while (1 && checkwrite == true ) { concurrency::wait(timeperiod*1000); qstring qdata = ui->textedit->toplaintext(); std::string data = qdata.tostdstring(); writefile(porthandler, data.c_str(), strlen(data.c_str()), &numwritten, null); } }
so when run program , program runs smoothly 2 or 3 minutes , crashes , errors "program has stopped working" , "program closed unexpectedly".when debug program , says "qt5core not loaded" or "qt5gui not loaded".
before ask here , did search on web . first did not use emit finished(qstring)
signal , instead directly manipulated gui objects inside startread()
method.(i did ui->text_edit->settext(some qstring)
).but after search learn can not change gui objects thread decided use signal , slot mechanism , has not solved problem far.i same error again , again.please tell me doing wrong . if need further explanation, happily give more details.
Comments
Post a Comment