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. QObject EventLoop
QtWS25 Last Chance

QObject EventLoop

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 1.5k 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.
  • I Offline
    I Offline
    inforathinam
    wrote on last edited by VRonin
    #1

    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 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by VRonin
      #2
      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)

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      kshegunovK 1 Reply Last reply
      5
      • VRoninV VRonin
        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)
        kshegunovK Offline
        kshegunovK Offline
        kshegunov
        Moderators
        wrote on last edited by
        #3

        @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.

        Read and abide by the Qt Code of Conduct

        VRoninV 1 Reply Last reply
        5
        • kshegunovK kshegunov

          @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.

          VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          @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

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          kshegunovK 1 Reply Last reply
          1
          • VRoninV VRonin

            @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

            kshegunovK Offline
            kshegunovK Offline
            kshegunov
            Moderators
            wrote on last edited by
            #5

            @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.

            Read and abide by the Qt Code of Conduct

            1 Reply Last reply
            1

            • Login

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