multithreading - Slow serial connection freezes QT GUI thread -


i'm working on project need communicate system rs485 serial devices. connection works , in separate thread qt gui thread.

i trying use signals/slots connect gui thread serial thread working whenever external device takes bit respond gui still locked until port finished , haven't been able figure out how fix it.

i'm starting serial thread in main.cpp this:

int main(int argc, char* argv[]) {     qapplication app(argc, argv);      qfile f(":/ts-controls.qss");     if (f.open(qiodevice::readonly)) {         app.setstylesheet(f.readall());         f.close();     }      (int = 0; < argc; ++i) {         if (qstring(argv[i]) == qstring("-h") ||             qstring(argv[i]) == qstring("--help") ||             qstring(argv[i]) == qstring("-help")) {              qdebug() << "usage:";             qdebug() << " -embedded : show in fullscreen mode";             qdebug() << " -no-embedded : show in desktop mode";             qdebug() << " -white : set every background white screenshots. ";              return 0;         }     }     mainwindow* mainwindow = new mainwindow();     modbusthread * thread = new modbusthread("/dev/ttyam1");     app.connect(thread->m_conn, signal(transactioncomplete(modbustransaction)), mainwindow->ref1, slot(receivetransaction(modbustransaction)), qt::directconnection);     app.connect(thread->m_conn, signal(busavailable(bool)), mainwindow->txqueue, slot(busavailable(bool)), qt::directconnection);     app.connect(mainwindow->txqueue, signal(elementunloaded(modbustransaction)), thread->m_conn, slot(loadtransaction(modbustransaction)), qt::directconnection);      thread->start();      mainwindow->show();     return app.exec(); } 

as can see, thread object of type modbusthread subclass of qthread. may notice i'm using qt::directconnect. tried using default autoconnect should queued since serial stuff going on in thread doesn't seem make difference either way in terms of problem. here modbusthread class:

    #include <qthread> #include <modbusconn.h> #include <modbustransaction.h>  #ifndef modbusthread_h #define modbusthread_h  class modbusthread : public qthread { public:     modbusthread(char * port);     modbusconn * m_conn; };  #endif // modbusthread_h  #include "modbusthread.h"  modbusthread::modbusthread(char * port) : qthread() {     this->m_conn = new modbusconn(this, port);        } 

now may wondering txqueue doing (it object listed in signal/slot connections in main.cpp if missed it). queue class modbustransaction datatype. idea since know actual modbus connection might busy @ given time can use queue holding buffer. ui widget load transaction request in queue. if modbus connection idle, txqueue pass along signal connection otherwise add queue. connection signals txqueue when available process transaction via busavailable signal.

somehow seems txqueue unable accept transactions added queue until connection object finishes.

i have done sleuthing via google , found page recommended in constructor of qthread subclass:

qobject::movetothread(this); 

i gave shot when run program none of signals/slots seem getting triggered since program isn't communicating device.

looking @ it, perhaps should rid of qthread subclass, create plain qthread move connection object it?

i'm new c++ , qt i'm sure there's approach bit off. i'd appreciate advice guys can offer.

qthread should subclassed extend threading behavior. think should read following article before trying use movetothread function: http://blog.qt.io/blog/2010/06/17/youre-doing-it-wrong/


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -