QT QThread Question



  • Hi,

    I have a qt project that uses libssh2 to communicate with a remote computer using local tunnel and terminal services. At first, the project subclasses Qthread (i know it is bad), and pretty much in the run() method of the class, i have something like this:

    do{
      localStateMachine();
    }while(1);
    

    In short, localStateMachine function gets call everytime to run the state-machine of my terminal service or tunnel service. This code works fine for me. But then I read somewhere online that one should not subclass QThread anymore, starting from qt4.4; so I decided to convert the class to QObject.

    My new code is changed to something like this:

    QTerminalService *term = new QTerminalService;
    QThread *thread = new QThread;
    QTimer *t = new QTimer;
    connect(t,SIGNAL(timeout()),term,SLOT(localStateMachine());
    t->moveToThread(thread);
    term->moveToThread(thread);
    t->start(10);
    thread.start();
    

    After changing the code to the new method, I often get IO error while calling a function from libssh2. A call to "libssh2_channel_read()" many times would not return data after a select() call on the socket descriptor. I am not sure if this is a bug in libssh2 or that the way I use QThread in the second method is not right. If you know of a better way to implement the second method, please let me know too.

    Thank you



  • I afraid you misunderstood what you read.
    There is nothing wrong with sub classing QThread.
    what is wrong - call to moveToThread(this);


Log in to reply