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. Multithreading
Qt 6.11 is out! See what's new in the release blog

Multithreading

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 402 Views 1 Watching
  • 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.
  • ODБOïO Offline
    ODБOïO Offline
    ODБOï
    wrote on last edited by ODБOï
    #1

    Hello,

    I did simple static library :

    class MY_SFTP : public QObject
    {
        Q_OBJECT
    public:
      //  ~~CN16K_SFTP(QObject *parent = nullptr);~~
      MY_SFTP(QObject *parent = nullptr);
    
        Q_PROPERTY(bool connected READ connected WRITE setConnected NOTIFY connectedChanged)
        bool connected()const{
            return m_connected;
        }
        void setConnected(const bool &co){
            if(m_connected!=co){
                m_connected = co;
                emit connectedChanged(m_connected);
            }
        }
    public slots:
        void connectToServer(QString url){ /*this will take 5 seconds*/ }
    signals:
        void connectedChanged(bool);
      private :
        bool m_connected;
     };
    

    I import and use it in another project. I use it i a new QThread to not freeze my GUI, like this :

    SftpUser::SftpUser(QObject *parent) : QObject(parent)
    {
        wt = new QThread();
        m_sftp = new MY_SFTP();
        m_sftp->moveToThread(wt);
    }
    

    Is this a good approch or the QThread should be created in the lib itself ?

    sierdzioS 1 Reply Last reply
    0
    • ODБOïO ODБOï

      Hello,

      I did simple static library :

      class MY_SFTP : public QObject
      {
          Q_OBJECT
      public:
        //  ~~CN16K_SFTP(QObject *parent = nullptr);~~
        MY_SFTP(QObject *parent = nullptr);
      
          Q_PROPERTY(bool connected READ connected WRITE setConnected NOTIFY connectedChanged)
          bool connected()const{
              return m_connected;
          }
          void setConnected(const bool &co){
              if(m_connected!=co){
                  m_connected = co;
                  emit connectedChanged(m_connected);
              }
          }
      public slots:
          void connectToServer(QString url){ /*this will take 5 seconds*/ }
      signals:
          void connectedChanged(bool);
        private :
          bool m_connected;
       };
      

      I import and use it in another project. I use it i a new QThread to not freeze my GUI, like this :

      SftpUser::SftpUser(QObject *parent) : QObject(parent)
      {
          wt = new QThread();
          m_sftp = new MY_SFTP();
          m_sftp->moveToThread(wt);
      }
      

      Is this a good approch or the QThread should be created in the lib itself ?

      sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      @LeLev said in Multithreading:

      Is this a good approch or the QThread should be created in the lib itself ?

      It's good. This way you leave users of your library a choice - they can use your class in thread or not.

      By the way: your class name does not match the name of the constructor (which means that it is not a constructor). Probably a copy-paste error, but I point it out just in case.

      (Z(:^

      1 Reply Last reply
      4
      • ODБOïO Offline
        ODБOïO Offline
        ODБOï
        wrote on last edited by
        #3

        Thank you @sierdzio.
        class name edited :)

        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