QObject EventLoop



  • Hi ,

    I have a QObject class like this:

    class Dummy:public QObject
    {
        Q_OBJECT
    public:
        Dummy()
        {
            splashview = new SplashView;
        }
    
        ~Dummy()
        {
    
        }
    public slots:
        void handleDashboard()
        {  
            splashview->showMessage("Loading X...");
        }
    
        void handleSystem()
        {
            splashview->showMessage("Loading Y.....");
        }
    
        void handleAnalysis()
        {
            splashview->showMessage("Loading Z...");
        }
    private:
        SplashView *splashview;
    
    };
    
     QThread *pluginThread = new QThread;
            Worker *worker = new Worker;
            IGSxGUI::Dummy *widget = new IGSxGUI::Dummy;
    
            QObject::connect(pluginThread,SIGNAL(started()),
                             worker, SLOT(doWork()));
            QObject::connect(worker, SIGNAL(updateSystem()),
                             widget, SLOT(handleSystem()));
            QObject::connect(worker, SIGNAL(updateDashboard()),
                             widget, SLOT(handleDashboard()));
            QObject::connect(worker, SIGNAL(updateAnalysis()),
                             widget, SLOT(handleAnalysis()));
            worker->moveToThread(pluginThread);
            pluginThread->start();
    

    Problem:
    SplashView is anoth UI Widget.
    But when updateDashboard() signal is emitted from worker object, then handleDashboard() slot in Dummy is called.
    But it is updating the Splashview UI with showMessaget()

    showMessage(const QString text)
    {
     ui->lable->setText(text);
    }
    

    Do the event loop has to be run for QObject? or not , If yes How?



    1. you are leaking every single object you are creating in the code above.
    2. you never call splashview->show() so it will never pop up
    3. yes, you need an event loop in the main thread otherwise queued slots can't be executed. it normally is started in the main() calling QApplication::exec()
    4. You probably want to call moveToThread before you do the connections (not sure if Qt is smart enough to change them to queued connections)

  • Qt Champions 2016

    @VRonin said in QObject EventLoop:

    not sure if Qt is smart enough to change them to queued connections

    The remark's moot. The thread affinity check is made at the time the signal's emitted, not when the connection's made.



  • @kshegunov said in QObject EventLoop:

    The thread affinity check is made at the time the signal's emitted

    You never stop learning, I always tought it was at time of connect() call. good to know


  • Qt Champions 2016

    @VRonin said in QObject EventLoop:

    I always tought it was at time of connect() call

    If memory serves me, it is in QMetaObject::activate, which is the root point for all meta calls.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.