Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QThread with a GUI



  • Good morning, everyone,
    still in my learning with QThread, I have a problem, like how to adapt a QThread with a graphical interface;
    here is my problem: I have a server and I want to use the thread in my server class, knowing that it has several functions in its breast, example of the code:

    
    
    class server
    {
        public:
    
        serveur(QObject *parent);
    
        void function1();
        void function2();
        void function3();
        void function4();
    
        signals:
        //
    
        public slot:
        //
    
        private:
    
        int number
        QString string;
    }
    

    now I'm asking myself a question, do I have to make the Server class inherit QThread to execute several functions simultaneously?
    and if so, how to execute function1(), function2() and function5() at the same time?

    Thank you in advance for your help



  • This post is deleted!

  • Lifetime Qt Champion

    Hi,

    Before starting to play with threads, take a look at the QtConcurrent module. It might do what you need without having to dive into the subtleties of threading.


  • Qt Champions 2017

    One option as suggested by @SGaist

    1. QtConcurrent module. Still if you want to
    2. Inherit your object from QObject. Create thread object, Move your object to QThread.
    3. Last option is you have inherit from QThread and implement run method.
      If you want to run all the three methods at same time, multiple thread objects are required.

Log in to reply