Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QT QThread Question
Servers for Qt installer are currently down

QT QThread Question

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 723 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tpham3783
    wrote on last edited by tpham3783
    #1

    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

    1 Reply Last reply
    0
    • A Offline
      A Offline
      alex_malyu
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved